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

Allow to disable digits in Faker::Internet.password method #3033

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

Currently, a digit is always added to the string generated by Faker::Interner.password. There's currently no way to disable this behavior.

Also, with the current behavior, running Faker::Internet.password(min_length: 2, max_length: 2, mix_case: true) will return a password of length 3, as a digit is always added to the string, in addition to the uppercase and lowercase letters.

Changes proposed in this pull request

This PR allows to disable the use of digits (and the auto-addition of one) when generating passwords. By default, a digit is added, but this can be disabled by setting the digits option to false. Also, when the digits option is set to true (current and default behavior), the required length of the password is updated to reflect the presence of the digit.

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 idea makes sense.

Thank you very much!

@francktrouillez francktrouillez force-pushed the feature/allow-to-enable-disable-digits-in-faker-internet-password branch from 2313e3f to 17967e3 Compare December 6, 2024 19:05
This change allows to allow or not digits inside the password. If `digits: true`, a digit is automatically added.
@thdaraujo thdaraujo force-pushed the feature/allow-to-enable-disable-digits-in-faker-internet-password branch from 17967e3 to 4a8fb7b Compare January 7, 2025 00:29
@stefannibrasil
Copy link
Contributor

What is the use case for passwords without a digit? I am not sure that's something popular enough to be supported here. If that functionality is needed, it seems best to me to use [Faker::Alphanumeric.alphanumeric](https://github.com/faker-ruby/faker/blob/main/doc/default/alphanumeric.md?plain=1) with 0 digits.

@francktrouillez
Copy link
Author

@stefannibrasil

Thanks for the answer!

To be completely honest, I thought it would be useful to have such thing when working on #3034, because a digit is always added (leading to a wrong required length).

I believe it might happen that you don't want to have one. I don't know all the use cases obviously, but I don't see the harm supporting it.

Is there a specific reason why we wouldn't want to allow that?

Faker::Alphanumeric.alphanumeric looks like a great alternative, but doesn't offer the special characters nor the uppercase letters.

Let me know if I missed something, or if I can help with anything else!

@stefannibrasil
Copy link
Contributor

Faker is currently focused on performance and organization of all the existing generators. We already have a lot of generators, and adding one more feature adds to the complexity of focusing on our goal. One of our projects is to allow extensible plugins where the community can create plugins for niche scenarios like this one, and the creator maintains it instead of us.

Bugs are still valid. I will review the bug this week.

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.

3 participants