Fix random_key()

This commit is contained in:
Visman 2017-01-09 21:16:01 +07:00
parent 24522067ce
commit 3414c6a0ce

View file

@ -1162,7 +1162,10 @@ function random_key($len, $readable = false, $hash = false)
$key .= (string) mcrypt_create_iv($len, MCRYPT_DEV_URANDOM);
}
if (strlen($key) < $len && function_exists('openssl_random_pseudo_bytes')) {
$key .= (string) openssl_random_pseudo_bytes($len);
$tmp = (string) openssl_random_pseudo_bytes($len, $strong);
if ($strong) {
$key .= $tmp;
}
}
if (strlen($key) < $len) {
throw new \Exception('Could not gather sufficient random data');