Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #10591 - System-generated password does not meet Password Security Settings #10592

Open
wants to merge 1 commit into
base: hotfix
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions modules/Users/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2272,19 +2272,45 @@ public static function generatePassword()
$NUMBER = "0123456789";
$UPPERCASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$SPECIAL = '~!@#$%^&*()_+=-{}|';
$condition = 0;

// Get password requirements
$length = 6;
if (isset($res['minpwdlength']) && is_numeric($res['minpwdlength']) && $res['minpwdlength'] > $length) {
$length = $res['minpwdlength'];
}

$charBKT .= $UPPERCASE . $LOWERCASE . $NUMBER;
$requirements = [];
$password = "";
$length = '6';

// Create random characters for the ones that doesnt have requirements
for ($i = 0; $i < $length - $condition; $i++) { // loop and create password
$password = $password . substr($charBKT, mt_rand() % strlen($charBKT), 1);
// Set one Upper, Lower, Number or Special if are required
if (isset($res['oneupper']) && $res['oneupper']) {
$requirements[] = $UPPERCASE[mt_rand(0, strlen($UPPERCASE) - 1)];
}
if (isset($res['onelower']) && $res['onelower']) {
$requirements[] = $LOWERCASE[mt_rand(0, strlen($LOWERCASE) - 1)];
}
if (isset($res['onenumber']) && $res['onenumber']) {
$requirements[] = $NUMBER[mt_rand(0, strlen($NUMBER) - 1)];
}
if (isset($res['onespecial']) && $res['onespecial']) {
$requirements[] = $SPECIAL[mt_rand(0, strlen($SPECIAL) - 1)];
$charBKT .= $SPECIAL;
}
$password .= implode('', $requirements);

// Create other random characters
for ($i = 0; $i < $length - count($requirements); $i++) { // loop and create password
$password .= $charBKT[mt_rand(0, strlen($charBKT) - 1)];
}

// Shuffle password characters
$password = str_shuffle($password);

return $password;
}


/**
* Send new password or link to user
*
Expand Down