1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-13 17:45:55 +00:00

make_password: generate longer passwords by default, use better random function if available

This commit is contained in:
Andrew Dolgov
2019-03-05 20:16:50 +03:00
parent ef6d2b8a4e
commit 16a9bdc387
3 changed files with 14 additions and 7 deletions

View File

@@ -55,21 +55,28 @@
//
}
function make_password($length = 8) {
function make_password($length = 12) {
$password = "";
$possible = "0123456789abcdfghjkmnpqrstvwxyzABCDFGHJKMNPQRSTVWXYZ*%+^";
$i = 0;
$i = 0;
while ($i < $length) {
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
try {
$idx = function_exists("random_int") ? random_int(0, strlen($possible) - 1) : mt_rand(0, strlen($possible) - 1);
} catch (Exception $e) {
$idx = mt_rand(0, strlen($possible) - 1);
}
$char = substr($possible, $idx, 1);
if (!strstr($password, $char)) {
$password .= $char;
$i++;
}
}
return $password;
}