2
0
forked from Wavyzz/dolibarr

Fix for php8

This commit is contained in:
Laurent Destailleur
2020-10-30 03:25:33 +01:00
parent d7225327e7
commit f22017080d
2 changed files with 17 additions and 9 deletions

View File

@@ -467,15 +467,18 @@ function getRandomPassword($generic = false, $replaceambiguouschars = null, $len
{
$max = strlen($lowercase) - 1;
for ($x = 0; $x < $nbofchar; $x++) {
$randomCode .= $lowercase{random_int(0, $max)};
$tmp = random_int(0, $max);
$randomCode .= $lowercase[$tmp];
}
$max = strlen($uppercase) - 1;
for ($x = 0; $x < $nbofchar; $x++) {
$randomCode .= $uppercase{random_int(0, $max)};
$tmp = random_int(0, $max);
$randomCode .= $uppercase[$tmp];
}
$max = strlen($numbers) - 1;
for ($x = 0; $x < $nbofcharlast; $x++) {
$randomCode .= $numbers{random_int(0, $max)};
$tmp = random_int(0, $max);
$randomCode .= $numbers[$tmp];
}
$generated_password=str_shuffle($randomCode);
@@ -484,15 +487,18 @@ function getRandomPassword($generic = false, $replaceambiguouschars = null, $len
{
$max = strlen($lowercase) - 1;
for ($x = 0; $x < $nbofchar; $x++) {
$randomCode .= $lowercase{mt_rand(0, $max)};
$tmp = mt_rand(0, $max);
$randomCode .= $lowercase[$tmp];
}
$max = strlen($uppercase) - 1;
for ($x = 0; $x < $nbofchar; $x++) {
$randomCode .= $uppercase{mt_rand(0, $max)};
$tmp = mt_rand(0, $max);
$randomCode .= $uppercase[$tmp];
}
$max = strlen($numbers) - 1;
for ($x = 0; $x < $nbofcharlast; $x++) {
$randomCode .= $numbers{mt_rand(0, $max)};
$tmp = mt_rand(0, $max);
$randomCode .= $numbers[$tmp];
}
$generated_password=str_shuffle($randomCode);
@@ -516,11 +522,13 @@ function getRandomPassword($generic = false, $replaceambiguouschars = null, $len
$max = strlen($numbers) - 1;
if (function_exists('random_int')) // Cryptographic random
{
$generated_password=str_replace($replaceambiguouschars, $numbers{random_int(0, $max)}, $generated_password);
$tmp = random_int(0, $max);
$generated_password=str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
}
else
{
$generated_password=str_replace($replaceambiguouschars, $numbers{mt_rand(0, $max)}, $generated_password);
$tmp = random_int(0, $max);
$generated_password=str_replace($replaceambiguouschars, $numbers[$tmp], $generated_password);
}
}