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

Conversation

crystaldaking
Copy link

What does it do?

Updated the password generation function using a truly random string

Why is it needed?

I am deeply convinced that the more a password looks like a hash, the less it attracts the attention of hackers. Moreover, this implementation uses a truly random string in contrast to the stock implementation

The options parameter as part of password generation is a rather useless parameter. It is not safe to specify salt, any other parameters simply do not occur to me. As an option, I left the implementation of the classic alphabet password that can be invoked using options

How to test

Standard tests work, no logic is affected.
You can also test password generation in the user control panel

Related issue(s)/PR(s)

#15740

@cla-bot cla-bot bot added the cla-signed CLA confirmed for contributors to this PR. label Nov 8, 2021
@Ibochkarev Ibochkarev added the pr/review-needed Pull request requires review and testing. label Nov 8, 2021
@Ibochkarev Ibochkarev added this to the v3.0.0-beta1 milestone Nov 8, 2021
Copy link
Collaborator

@Ibochkarev Ibochkarev left a comment

Choose a reason for hiding this comment

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

Before:

изображение

After:

изображение

@opengeek opengeek removed this from the v3.0.0-beta1 milestone Nov 8, 2021
@JoshuaLuckers
Copy link
Contributor

@Mark-H I would like your opinion on this change.

if ($options['alphabet']) {
$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 substr(bin2hex(random_bytes($length)),$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(bin2hex(random_bytes($length)),$length);
return substr(bin2hex(random_bytes($length)), $length);

@Mark-H
Copy link
Collaborator

Mark-H commented Jan 16, 2022

Other than the phpcs issues I don't have a strong opinion on this - the use of bin2hex(random_bytes()) is valid for this type of random generation. Ideally people don't keep using these random passwords anyway.

The modUserTest::testGeneratePassword tests do need to be updated it seems.

@Mark-H Mark-H added this to the v3.0.0-rc2 milestone Jan 19, 2022
Copy link
Collaborator

@Mark-H Mark-H left a comment

Choose a reason for hiding this comment

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

Tests need to be updated to match new implementation.

@opengeek opengeek modified the milestones: v3.0.0-rc2, v3.0.0-pl Feb 3, 2022
@opengeek opengeek removed this from the v3.0.0 milestone Mar 29, 2022
@JoshuaLuckers
Copy link
Contributor

@crystaldaking would it be possible for you to update the Unit Tests to match your implementation?

@Mark-H Mark-H removed the pr/review-needed Pull request requires review and testing. label Jan 30, 2023
@Mark-H Mark-H added this to the v3.1.0 milestone Jan 30, 2023
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.

@Ibochkarev
Copy link
Collaborator

@crystaldaking ping...

@Mark-H
Copy link
Collaborator

Mark-H commented Feb 10, 2024

As this PR has gone stale, I recreated it at #16521.

@Mark-H Mark-H closed this Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed CLA confirmed for contributors to this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants