Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Merge pull request #2 from zendframework/master
Browse files Browse the repository at this point in the history
Update to 1.17
  • Loading branch information
erdraug committed Jan 12, 2016
2 parents 2dc5433 + 8142957 commit 65251e9
Show file tree
Hide file tree
Showing 11 changed files with 227 additions and 31 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Master: [![Build Status](https://api.travis-ci.org/zendframework/zf1.png?branch=
RELEASE INFORMATION
===================

Zend Framework 1.12.17dev Release.
Zend Framework 1.12.18dev Release.
Released on MMM DD, YYYY.

IMPORTANT FIXES FOR 1.12.17
IMPORTANT FIXES FOR 1.12.18
---------------------------

See http://framework.zend.com/changelog for full details.
Expand Down
29 changes: 17 additions & 12 deletions library/Zend/Captcha/Word.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
/** @see Zend_Captcha_Base */
require_once 'Zend/Captcha/Base.php';

/** @see Zend_Crypt_Math */
require_once 'Zend/Crypt/Math.php';

/**
* Word-based captcha adapter
*
Expand All @@ -39,10 +42,10 @@ abstract class Zend_Captcha_Word extends Zend_Captcha_Base
/**#@+
* @var array Character sets
*/
static $V = array("a", "e", "i", "o", "u", "y");
static $VN = array("a", "e", "i", "o", "u", "y","2","3","4","5","6","7","8","9");
static $C = array("b","c","d","f","g","h","j","k","m","n","p","q","r","s","t","u","v","w","x","z");
static $CN = array("b","c","d","f","g","h","j","k","m","n","p","q","r","s","t","u","v","w","x","z","2","3","4","5","6","7","8","9");
static public $V = array("a", "e", "i", "o", "u", "y");
static public $VN = array("a", "e", "i", "o", "u", "y","2","3","4","5","6","7","8","9");
static public $C = array("b","c","d","f","g","h","j","k","m","n","p","q","r","s","t","u","v","w","x","z");
static public $CN = array("b","c","d","f","g","h","j","k","m","n","p","q","r","s","t","u","v","w","x","z","2","3","4","5","6","7","8","9");
/**#@-*/

/**
Expand Down Expand Up @@ -175,7 +178,7 @@ public function setWordlen($wordlen)
*
* @return string
*/
public function getId ()
public function getId()
{
if (null === $this->_id) {
$this->_setId($this->_generateRandomId());
Expand All @@ -189,7 +192,7 @@ public function getId ()
* @param string $id
* @return Zend_Captcha_Word
*/
protected function _setId ($id)
protected function _setId($id)
{
$this->_id = $id;
return $this;
Expand Down Expand Up @@ -250,7 +253,7 @@ public function setUseNumbers($_useNumbers)
$this->_useNumbers = $_useNumbers;
return $this;
}

/**
* Get session object
*
Expand Down Expand Up @@ -280,7 +283,7 @@ public function getSession()
public function setSession(Zend_Session_Namespace $session)
{
$this->_session = $session;
if($session) {
if ($session) {
$this->_keepSession = true;
}
return $this;
Expand Down Expand Up @@ -326,10 +329,12 @@ protected function _generateWord()
$vowels = $this->_useNumbers ? self::$VN : self::$V;
$consonants = $this->_useNumbers ? self::$CN : self::$C;

$totIndexCon = count($consonants) - 1;
$totIndexVow = count($vowels) - 1;
for ($i=0; $i < $wordLen; $i = $i + 2) {
// generate word with mix of vowels and consonants
$consonant = $consonants[array_rand($consonants)];
$vowel = $vowels[array_rand($vowels)];
$consonant = $consonants[Zend_Crypt_Math::randInteger(0, $totIndexCon, true)];
$vowel = $vowels[Zend_Crypt_Math::randInteger(0, $totIndexVow, true)];
$word .= $consonant . $vowel;
}

Expand All @@ -347,7 +352,7 @@ protected function _generateWord()
*/
public function generate()
{
if(!$this->_keepSession) {
if (!$this->_keepSession) {
$this->_session = null;
}
$id = $this->_generateRandomId();
Expand All @@ -359,7 +364,7 @@ public function generate()

protected function _generateRandomId()
{
return md5(mt_rand(0, 1000) . microtime(true));
return md5(Zend_Crypt_Math::randBytes(32));
}

/**
Expand Down
2 changes: 0 additions & 2 deletions library/Zend/Cloud/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class Zend_Cloud_AbstractFactory
{
/**
* Constructor
*
* @return void
*/
private function __construct()
{
Expand Down
5 changes: 2 additions & 3 deletions library/Zend/Cloud/QueueService/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class Zend_Cloud_QueueService_Factory extends Zend_Cloud_AbstractFactory

/**
* Constructor
*
* @return void
*/
private function __construct()
{
Expand All @@ -51,7 +49,8 @@ private function __construct()
* Retrieve QueueService adapter
*
* @param array $options
* @return void
* @return null|Zend_Cloud_DocumentService_Adapter|Zend_Cloud_QueueService_Adapter|Zend_Cloud_StorageService_Adapter
* @throws Zend_Cloud_QueueService_Exception
*/
public static function getAdapter($options = array())
{
Expand Down
100 changes: 94 additions & 6 deletions library/Zend/Crypt/Math.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,109 @@ public function rand($minimum, $maximum)
}
$rand = '';
$i2 = strlen($maximum) - 1;
for ($i = 1;$i < $i2;$i++) {
$rand .= mt_rand(0,9);
for ($i = 1; $i < $i2; $i++) {
$rand .= mt_rand(0, 9);
}
$rand .= mt_rand(0,9);
$rand .= mt_rand(0, 9);
return $rand;
}

/**
* Return a random strings of $length bytes
*
* @param integer $length
* @param boolean $strong
* @return string
*/
public static function randBytes($length, $strong = false)
{
$length = (int) $length;
if ($length <= 0) {
return false;
}
if (function_exists('openssl_random_pseudo_bytes')) {
$bytes = openssl_random_pseudo_bytes($length, $usable);
if ($strong === $usable) {
return $bytes;
}
}
if (function_exists('mcrypt_create_iv')) {
$bytes = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
if ($bytes !== false && strlen($bytes) === $length) {
return $bytes;
}
}
if (file_exists('/dev/urandom') && is_readable('/dev/urandom')) {
$frandom = fopen('/dev/urandom', 'r');
if ($frandom !== false) {
return fread($frandom, $length);
}
}
if (true === $strong) {
require_once 'Zend/Crypt/Exception.php';
throw new Zend_Crypt_Exception(
'This PHP environment doesn\'t support secure random number generation. ' .
'Please consider installing the OpenSSL and/or Mcrypt extensions'
);
}
$rand = '';
for ($i = 0; $i < $length; $i++) {
$rand .= chr(mt_rand(0, 255));
}
return $rand;
}

/**
* Return a random integer between $min and $max
*
* @param integer $min
* @param integer $max
* @param boolean $strong
* @return integer
*/
public static function randInteger($min, $max, $strong = false)
{
if ($min > $max) {
require_once 'Zend/Crypt/Exception.php';
throw new Zend_Crypt_Exception(
'The min parameter must be lower than max parameter'
);
}
$range = $max - $min;
if ($range == 0) {
return $max;
} elseif ($range > PHP_INT_MAX || is_float($range)) {
require_once 'Zend/Crypt/Exception.php';
throw new Zend_Crypt_Exception(
'The supplied range is too great to generate'
);
}
// calculate number of bits required to store range on this machine
$r = $range;
$bits = 0;
while ($r) {
$bits++;
$r >>= 1;
}
$bits = (int) max($bits, 1);
$bytes = (int) max(ceil($bits / 8), 1);
$filter = (int) ((1 << $bits) - 1);
do {
$rnd = hexdec(bin2hex(self::randBytes($bytes, $strong)));
$rnd &= $filter;
} while ($rnd > $range);
return ($min + $rnd);
}

/**
* Get the big endian two's complement of a given big integer in
* binary notation
*
* @param string $long
* @return string
*/
public function btwoc($long) {
public function btwoc($long)
{
if (ord($long[0]) > 127) {
return "\x00" . $long;
}
Expand All @@ -84,7 +172,8 @@ public function btwoc($long) {
* @param string $binary
* @return string
*/
public function fromBinary($binary) {
public function fromBinary($binary)
{
return $this->_math->binaryToInteger($binary);
}

Expand All @@ -98,5 +187,4 @@ public function toBinary($integer)
{
return $this->_math->integerToBinary($integer);
}

}
Loading

0 comments on commit 65251e9

Please sign in to comment.