Skip to content
This repository has been archived by the owner on Nov 14, 2019. It is now read-only.

Commit

Permalink
Use mt_rand() instead of microtime()
Browse files Browse the repository at this point in the history
  • Loading branch information
crazy-max committed Sep 28, 2013
1 parent 45ed32a commit d1ead1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ An example is available in ``index.php`` file :
**checkPassword** - Check a hash with the password given.<br />
**encrypt** - Generate a symectric encryption string with the blowfish algorithm and an encryption key in CFB mode.<br />
**decrypt** - Return the decrypted string generated from the encrypt method.<br />
**random** - Generate secure random bytes with 5 methods : mcrypt_create_iv, openssl_random_pseudo_bytes, GetRandom() from CAPICOM Microsoft class, /dev/urandom on Unix systems or microtime() and getmypid() functions.<br />
**random** - Generate secure random bytes with 5 methods : mcrypt_create_iv, openssl_random_pseudo_bytes, GetRandom() from CAPICOM Microsoft class, /dev/urandom on Unix systems or mt_rand() and getmypid() functions.<br />

**getVersion** - Get the CwsCrypto version.<br />
**setDefaultMode** - Set the default mode for hashing/check password.<br />
Expand Down
12 changes: 6 additions & 6 deletions class.cws.crypto.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author Cr@zy
* @copyright 2013, Cr@zy
* @license GNU LESSER GENERAL PUBLIC LICENSE
* @version 1.1
* @version 1.2
* @link https://github.com/crazy-max/CwsCrypto
*
*/
Expand Down Expand Up @@ -73,7 +73,7 @@ class CwsCrypto
* CwsCrypto version.
* @var string
*/
private $version = "1.1";
private $version = "1.2";

/**
* Default mode for hashing/check password
Expand Down Expand Up @@ -399,7 +399,7 @@ public function decrypt($data, $key=null)
/**
* Generate secure random bytes with 5 methods : mcrypt_create_iv,
* openssl_random_pseudo_bytes, GetRandom() from CAPICOM Microsoft class,
* /dev/urandom on Unix systems or microtime() and getmypid() functions.
* /dev/urandom on Unix systems or mt_rand() and getmypid() functions.
* @param int $length : The length of random bytes
* @param boolean $base64 : Encodes random bytes with MIME base64
* @return string|NULL : The random bytes
Expand Down Expand Up @@ -446,15 +446,15 @@ public static function random($length=32, $base64=true)
}
}

// Otherwise use microtime() and getmypid() functions
// Otherwise use mt_rand() and getmypid() functions
if (strlen($bytes) < $length) {
$bytes = '';
$state = microtime();
$state = mt_rand();
if (function_exists('getmypid')) {
$state .= getmypid();
}
for ($i = 0; $i < $length; $i += 16) {
$state = md5(microtime() . $state);
$state = md5(mt_rand() . $state);
$bytes .= pack('H*', md5($state));
}
return substr($bytes, 0, $length);
Expand Down

0 comments on commit d1ead1d

Please sign in to comment.