ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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...
 
static getBytes (int $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() [1/2]

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.

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

References $i.

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

+ Here is the caller graph for this function:

◆ getBytes() [2/2]

static ilPasswordUtils::getBytes ( int  $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.

16 : string
17 {
18 try {
19 return random_bytes($length);
20 } catch (Throwable $ex) {
21 if (!defined('PHP_WINDOWS_VERSION_BUILD') && extension_loaded('openssl')) {
22 $secure = null;
23 $rand = openssl_random_pseudo_bytes($length, $secure);
24 if (false !== $rand && $secure === true) {
25 return $rand;
26 }
27 }
28
29 $rand = '';
30 for ($i = 0; $i < $length; ++$i) {
31 $rand .= chr(random_int(0, 255));
32 }
33
34 return $rand;
35 }
36 }

References $i.


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