Using random_int directly

This commit is contained in:
Philipp Holzer 2018-11-05 21:15:30 +01:00
parent c94936a149
commit 049cd963f3
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
2 changed files with 5 additions and 77 deletions

View file

@ -483,21 +483,16 @@ class Crypto
*
* @param string $digits The count of digits
* @return int The random Digits
*
* @throws \Exception In case 'random_int' isn't usable
*/
public static function randomDigits($digits)
{
$rn = '';
if (!function_exists('random_int')) {
// using rand() function for PHP 5.x compatibility
for ($i = 0; $i < $digits; $i++) {
$rn .= rand(0, 9);
}
} else {
// generating cryptographically secure pseudo-random integers
for ($i = 0; $i < $digits; $i++) {
$rn .= random_int(0, 9);
}
// generating cryptographically secure pseudo-random integers
for ($i = 0; $i < $digits; $i++) {
$rn .= random_int(0, 9);
}
return $rn;