|
@@ 47-52 (lines=6) @@
|
| 44 |
|
|
| 45 |
|
if (function_exists('openssl_random_pseudo_bytes')) { |
| 46 |
|
// use openssl lib if it is installed |
| 47 |
|
for ($i = 0, $lc = strlen($chars) - 1; $i < $length; $i++) { |
| 48 |
|
$bytes = openssl_random_pseudo_bytes(PHP_INT_SIZE); |
| 49 |
|
$hex = bin2hex($bytes); // hex() doubles the length of the string |
| 50 |
|
$rand = abs(hexdec($hex) % $lc); // random integer from 0 to $lc |
| 51 |
|
$str .= $chars[$rand]; // random character in $chars |
| 52 |
|
} |
| 53 |
|
} elseif ($fp = fopen('/dev/urandom', 'rb')) { |
| 54 |
|
// attempt to use /dev/urandom if it exists but openssl isn't available |
| 55 |
|
for ($i = 0, $lc = strlen($chars) - 1; $i < $length; $i++) { |
|
@@ 55-60 (lines=6) @@
|
| 52 |
|
} |
| 53 |
|
} elseif ($fp = fopen('/dev/urandom', 'rb')) { |
| 54 |
|
// attempt to use /dev/urandom if it exists but openssl isn't available |
| 55 |
|
for ($i = 0, $lc = strlen($chars) - 1; $i < $length; $i++) { |
| 56 |
|
$bytes = fread($fp, PHP_INT_SIZE); |
| 57 |
|
$hex = bin2hex($bytes); // hex() doubles the length of the string |
| 58 |
|
$rand = abs(hexdec($hex) % $lc); // random integer from 0 to $lc |
| 59 |
|
$str .= $chars[$rand]; // random character in $chars |
| 60 |
|
} |
| 61 |
|
fclose($fp); |
| 62 |
|
} else { |
| 63 |
|
throw new \Gojira\Framework\Exception\LocalizedException( |