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

Ensure Faker::Internet.password method behavior is consistent with length parameters #3034

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

francktrouillez
Copy link

@francktrouillez francktrouillez commented Dec 6, 2024

Motivation / Background

When using Faker::Interner.password, the min_length and max_length options are not always respected.

For instance, running the following snippet will give password out of the desired length range:

Faker::Internet.password(min_length: 2, max_length: 2) # => "Pa1" => 3 characters while I was expecting 2
Faker::Internet.password(min_length: 1, max_length: 1, mix_case: false) # => "9n" => 2 characters while I was expecting 1
Faker::Internet.password(min_length: 1, max_length: 1, mix_case: false, special_characters: true) # => "!5u" => 3 characters while I was expecting 1
Faker::Internet.password(min_length: 3, max_length: 3, mix_case: true, special_characters: true) # => "Y2#h" => 4 characters while I was expecting 3

This can lead to unexpected behavior when using the Faker::Internet.password method.

Changes proposed in this pull request

This PR fixes the issue by ensuring that the password generated respects the min_length and max_length options.

  • This is done so by specifying the behavior of the mix_case option from the Faker::Internet.password method, which is to either force-include an uppercase letter AND a lowercase letter if set to true, or to only use lowercase letters if set to false (without enforcing the presence of a letter).
  • This also removes the "force-addition" of digit, which lead to the password being one character longer than expected. I've opened a separate PR to enable or not the force-addition and the use of digits Allow to disable digits in Faker::Internet.password method #3033

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug, refactor something, or add a feature.
  • Tests and Rubocop are passing before submitting your proposed changes.

If you're proposing a new generator or locale:

  • [ ] Double-check the existing generators documentation to make sure the new generator you want to add doesn't already exist.
  • [ ] You've reviewed and followed the Contributing guidelines.

Closing notes

I'm open to any feedback or suggestions on how to improve this PR if this solution makes sense.

Thanks!

…ngth parameters

This change allows to make sure that the password respects the length specified in the parameters (i.e., if both `min_length` and `max_length` are set to 1, then the password should be 1 character long)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant