Fix regression in getRandomPassword
This commit is contained in:
parent
a066bbcd89
commit
91950ccbc7
@ -454,18 +454,21 @@ function getRandomPassword($generic=false)
|
|||||||
$uppercase = "ASDFGHJKLZXCVBNMQWERTYUIOP";
|
$uppercase = "ASDFGHJKLZXCVBNMQWERTYUIOP";
|
||||||
$numbers = "1234567890";
|
$numbers = "1234567890";
|
||||||
$randomCode = "";
|
$randomCode = "";
|
||||||
|
$nbofchar = round($length/3);
|
||||||
|
$nbofcharlast = ($length - 2*$nbofchar);
|
||||||
|
var_dump($nbofchar.'-'.$nbofcharlast);
|
||||||
if (function_exists('random_int')) // Cryptographic random
|
if (function_exists('random_int')) // Cryptographic random
|
||||||
{
|
{
|
||||||
$max = strlen($lowercase) - 1;
|
$max = strlen($lowercase) - 1;
|
||||||
for ($x = 0; $x < abs($length/3); $x++) {
|
for ($x = 0; $x < $nbofchar; $x++) {
|
||||||
$randomCode .= $lowercase{random_int(0, $max)};
|
$randomCode .= $lowercase{random_int(0, $max)};
|
||||||
}
|
}
|
||||||
$max = strlen($uppercase) - 1;
|
$max = strlen($uppercase) - 1;
|
||||||
for ($x = 0; $x < abs($length/3); $x++) {
|
for ($x = 0; $x < $nbofchar; $x++) {
|
||||||
$randomCode .= $uppercase{random_int(0, $max)};
|
$randomCode .= $uppercase{random_int(0, $max)};
|
||||||
}
|
}
|
||||||
$max = strlen($numbers) - 1;
|
$max = strlen($numbers) - 1;
|
||||||
for ($x = 0; $x < abs($length/3); $x++) {
|
for ($x = 0; $x < $nbofcharlast; $x++) {
|
||||||
$randomCode .= $numbers{random_int(0, $max)};
|
$randomCode .= $numbers{random_int(0, $max)};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,15 +477,15 @@ function getRandomPassword($generic=false)
|
|||||||
else // Old platform, non cryptographic random
|
else // Old platform, non cryptographic random
|
||||||
{
|
{
|
||||||
$max = strlen($lowercase) - 1;
|
$max = strlen($lowercase) - 1;
|
||||||
for ($x = 0; $x < abs($length/3); $x++) {
|
for ($x = 0; $x < $nbofchar; $x++) {
|
||||||
$randomCode .= $lowercase{mt_rand(0, $max)};
|
$randomCode .= $lowercase{mt_rand(0, $max)};
|
||||||
}
|
}
|
||||||
$max = strlen($uppercase) - 1;
|
$max = strlen($uppercase) - 1;
|
||||||
for ($x = 0; $x < abs($length/3); $x++) {
|
for ($x = 0; $x < $nbofchar; $x++) {
|
||||||
$randomCode .= $uppercase{mt_rand(0, $max)};
|
$randomCode .= $uppercase{mt_rand(0, $max)};
|
||||||
}
|
}
|
||||||
$max = strlen($numbers) - 1;
|
$max = strlen($numbers) - 1;
|
||||||
for ($x = 0; $x < abs($length/3); $x++) {
|
for ($x = 0; $x < $nbofcharlast; $x++) {
|
||||||
$randomCode .= $numbers{mt_rand(0, $max)};
|
$randomCode .= $numbers{mt_rand(0, $max)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user