mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-02-05 13:28:27 +00:00
Merge branch 'master' into php5
* master: Random: wrap crypt_random_string in a function_exists call
This commit is contained in:
commit
958430b5a8
@ -40,14 +40,18 @@
|
|||||||
* @link http://phpseclib.sourceforge.net
|
* @link http://phpseclib.sourceforge.net
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
// laravel is a PHP framework that utilizes phpseclib. laravel workbenches may, independently,
|
||||||
|
// have phpseclib as a requirement as well. if you're developing such a program you may encounter
|
||||||
|
// a "Cannot redeclare crypt_random_string()" error.
|
||||||
|
if (!function_exists('crypt_random_string')) {
|
||||||
|
/**
|
||||||
* "Is Windows" test
|
* "Is Windows" test
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
define('CRYPT_RANDOM_IS_WINDOWS', strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
|
define('CRYPT_RANDOM_IS_WINDOWS', strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a random string.
|
* Generate a random string.
|
||||||
*
|
*
|
||||||
* Although microoptimizations are generally discouraged as they impair readability this function is ripe with
|
* Although microoptimizations are generally discouraged as they impair readability this function is ripe with
|
||||||
@ -58,8 +62,8 @@ define('CRYPT_RANDOM_IS_WINDOWS', strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
|
|||||||
* @return String
|
* @return String
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function crypt_random_string($length)
|
function crypt_random_string($length)
|
||||||
{
|
{
|
||||||
if (CRYPT_RANDOM_IS_WINDOWS) {
|
if (CRYPT_RANDOM_IS_WINDOWS) {
|
||||||
// method 1. prior to PHP 5.3 this would call rand() on windows hence the function_exists('class_alias') call.
|
// method 1. prior to PHP 5.3 this would call rand() on windows hence the function_exists('class_alias') call.
|
||||||
// ie. class_alias is a function that was introduced in PHP 5.3
|
// ie. class_alias is a function that was introduced in PHP 5.3
|
||||||
@ -243,4 +247,5 @@ function crypt_random_string($length)
|
|||||||
$result.= $r;
|
$result.= $r;
|
||||||
}
|
}
|
||||||
return substr($result, 0, $length);
|
return substr($result, 0, $length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user