ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilPasswordUtils Class Reference
+ Collaboration diagram for ilPasswordUtils:

Static Public Member Functions

static getBytes ($length)
 Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.

Detailed Description

Definition at line 9 of file class.ilPasswordUtils.php.

Member Function Documentation

static ilPasswordUtils::getBytes (   $length)
static

Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.

Parameters
int$length
Returns
string A byte string

Definition at line 16 of file class.ilPasswordUtils.php.

Referenced by ilUserPasswordManager\encodePassword(), and ilBcryptPasswordEncoder\generateClientSalt().

{
if(!defined('PHP_WINDOWS_VERSION_BUILD') && extension_loaded('openssl'))
{
$secure = null;
$rand = openssl_random_pseudo_bytes($length, $secure);
if(false !== $rand && $secure === true)
{
return $rand;
}
}
if(extension_loaded('mcrypt'))
{
// PHP bug #55169
// @see https://bugs.php.net/bug.php?id=55169
if(
strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' ||
version_compare(PHP_VERSION, '5.3.7') >= 0
)
{
$rand = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
if($rand !== false && strlen($rand) === $length)
{
return $rand;
}
}
}
// Default random string generation
$rand = '';
for($i = 0; $i < $length; $i++)
{
$rand .= chr(mt_rand(0, 255));
}
return $rand;
}

+ Here is the caller graph for this function:


The documentation for this class was generated from the following file: