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

Change generatePassword() logic #15894

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
17 changes: 6 additions & 11 deletions core/src/Revolution/modUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -904,19 +904,14 @@ public function generatePassword($length = null, array $options = [])
if ($length < $passwordMinimumLength) {
$length = $passwordMinimumLength;
}
$options = array_merge([
'allowable_characters' => 'abcdefghjkmnpqrstuvxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789',
'srand_seed_multiplier' => 1000000,
], $options);

$ps_len = strlen($options['allowable_characters']);
srand((double)microtime() * $options['srand_seed_multiplier']);
$pass = '';
for ($i = 0; $i < $length; $i++) {
$pass .= $options['allowable_characters'][mt_rand(0, $ps_len - 1)];

if ($options['alphabet']) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may also require a check as I don't see the alphabet key being required elsewhere. So something like if (!empty($options['alphabet'])) { to avoid php warnings.

$alphabet = array_merge(range('a', 'z'), range('A', 'Z'));
shuffle($alphabet);
return substr(implode($alphabet),0,$length);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return substr(implode($alphabet),0,$length);
return substr(implode($alphabet), 0, $length);

}

return $pass;
return bin2hex(random_bytes($length));
}


Expand Down