Fix when random_int is not available

This commit is contained in:
Laurent Destailleur 2018-12-22 18:15:49 +01:00
parent 415fbc19af
commit 2b3fbecd49

View File

@ -514,8 +514,15 @@ function getRandomPassword($generic=false, $replaceambiguouschars=null)
{ {
$numbers = "ABCDEF"; $numbers = "ABCDEF";
$max = strlen($numbers) - 1; $max = strlen($numbers) - 1;
if (function_exists('random_int')) // Cryptographic random
{
$generated_password=str_replace($replaceambiguouschars, $numbers{random_int(0, $max)}, $generated_password); $generated_password=str_replace($replaceambiguouschars, $numbers{random_int(0, $max)}, $generated_password);
} }
else
{
$generated_password=str_replace($replaceambiguouschars, $numbers{mt_rand(0, $max)}, $generated_password);
}
}
return $generated_password; return $generated_password;
} }