ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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. More...
 

Detailed Description

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

Member Function Documentation

◆ getBytes()

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().

17  {
18  if(!defined('PHP_WINDOWS_VERSION_BUILD') && extension_loaded('openssl'))
19  {
20  $secure = null;
21  $rand = openssl_random_pseudo_bytes($length, $secure);
22  if(false !== $rand && $secure === true)
23  {
24  return $rand;
25  }
26  }
27 
28  if(extension_loaded('mcrypt'))
29  {
30  // PHP bug #55169
31  // @see https://bugs.php.net/bug.php?id=55169
32  if(
33  strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' ||
34  version_compare(PHP_VERSION, '5.3.7') >= 0
35  )
36  {
37  $rand = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
38  if($rand !== false && strlen($rand) === $length)
39  {
40  return $rand;
41  }
42  }
43  }
44 
45  // Default random string generation
46  $rand = '';
47  for($i = 0; $i < $length; $i++)
48  {
49  $rand .= chr(mt_rand(0, 255));
50  }
51  return $rand;
52  }
+ Here is the caller graph for this function:

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