You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reimplement internet.password() with more generation options #768
The passwords generated by internet.password() are not really secure.
Suggested solution
It would be nice if there would be various generation ways one can choose from.
secure (at least one of each: alpha, ALPHA, 0-9, special)
memorable (vowel and consonant alternating)
simple (any of alpha, ALPHA, 0-9)
words (a combination of random words)
Alternative
Remove the default pattern, that severely limits the password security
Additional context
No response
Reacted by Eric Cheng, ST-DDT, Mohammed AlHabbash, Nazmul Mumtahin, Daniel Pastrana, Vitalii Andrieiev, DivisionByZero, jacobg, Marcel Richter and Alden Quimby
The suggestions you made, would they all be implemented in a separate function? Or would there only be a single parameter like faker.internet.password({ mode: 'secure' })?
IMO it should be accessed via a single method with options.
Whether we use internal helper methods for each generation strategy doesn't really matter to me.
For parameter options, I would like something like https://passwordsgenerator.net/plus is doing. This would not be as simple with a single method and a mode.
The signature could also look something like this:
Based on my last comment:
If you provide all the groups (symbol, lower, upper, number) included and set a length less than 4, what would the expected behavior be? Throwing an error? Returning the string with one of each group?
This depends on the definition/description you are going to add to the parameters.
IMO include != required -> so you can have even long passwords without any of them. It's just a matter of chance.
If you are going for require, then I would throw.
I have read the include properties as required ("at least one of") since if you don't want to have any specific chars (don't include them at all) you can provide them via the banned chars array. But in this case, it would be best to name the properties appropriately (include => require).
If you want to work on this, feel free. I already have a branch that implements this if you want to take a look. I'm on my phone, so linking is hard right now.
If you want to work on this, feel free. I already have a branch that implements this if you want to take a look. I'm on my phone, so linking is hard right now.
Sorry, I didn't realize you already made a branch implementing this. From my understanding, we want to make it more lightweight than what you have currently?
Sadly, I can currently only answer that with "maybe".
We are about to wrap up development for v8.x (today) and start with v9.
For that we have some improvements planned that will likely also affect the implementation of password method (same as all other methods), so this might change in implementation, but not much in API.
Which feature is added by the branch, that you would like to use that is not possible with the current one?
Maybe we can recommend a workaround until then?
Hey guys, I'm building a library that can compute regex "intersections". Maybe that could be useful here. All these independent password constraints can easily be expressed with individual regex:
contains at least one number: /[0-9]/
contains at least one upper char: /[A-Z]/
at least 12 characters long: /^\w{12,}$/
...
It's much harder to write that with a single regex. But that's what regex intersections can do. With that you can turn multiple independent regex into a single one that exactly matches the intersection of all input regex. Once you have a single regex it should™ be easy to generate matching strings. Here is how the API looks like:
A downside is that the generated regex can be very large at the moment. I tried to do:
faker.internet.password({pattern: combinedRegex})
but I get a call stack overflow. It works with some other libraries though, which generate strings from regex. So this approach is definitely possible. I'm also trying to add my own generator to the library. That one has the luxury of skipping the "serialization" into a native JavaScript regex and instead generate strings directly from an internal representation:
Activity
xDivisionByZerox commentedon Jun 2, 2022
This looks interesting, I might provide a PR for this in the near future.
xDivisionByZerox commentedon Jun 18, 2022
The suggestions you made, would they all be implemented in a separate function? Or would there only be a single parameter like
faker.internet.password({ mode: 'secure' })?ST-DDT commentedon Jun 18, 2022
IMO it should be accessed via a single method with options.
Whether we use internal helper methods for each generation strategy doesn't really matter to me.
xDivisionByZerox commentedon Jun 18, 2022
For parameter options, I would like something like https://passwordsgenerator.net/plus is doing. This would not be as simple with a single method and a
mode.The signature could also look something like this:
xDivisionByZerox commentedon Jun 18, 2022
Based on my last comment:
If you provide all the groups (symbol, lower, upper, number) included and set a length less than 4, what would the expected behavior be? Throwing an error? Returning the string with one of each group?
ST-DDT commentedon Jun 18, 2022
This depends on the definition/description you are going to add to the parameters.
IMO include != required -> so you can have even long passwords without any of them. It's just a matter of chance.
If you are going for require, then I would throw.
xDivisionByZerox commentedon Jun 18, 2022
I have read the include properties as required ("at least one of") since if you don't want to have any specific chars (don't include them at all) you can provide them via the banned chars array. But in this case, it would be best to name the properties appropriately (include => require).
xDivisionByZerox commentedon Jun 18, 2022
Another approach would be to provide a different signature (advanced options only):
I really like this, because we can extend each character group with more options. Like a minimal count for example.
8 remaining items
xDivisionByZerox commentedon Mar 28, 2023
But
faker.string.fromRegExpis not out yet, tho. It's not even in the latest alpha release 🤔ejcheng commentedon Dec 13, 2023
@xDivisionByZerox Are you still willing to work on this?
xDivisionByZerox commentedon Dec 13, 2023
If you want to work on this, feel free. I already have a branch that implements this if you want to take a look. I'm on my phone, so linking is hard right now.
ST-DDT commentedon Dec 13, 2023
https://github.com/faker-js/faker/tree/refactor/internet/password
ejcheng commentedon Dec 13, 2023
Sorry, I didn't realize you already made a branch implementing this. From my understanding, we want to make it more lightweight than what you have currently?
jacobg commentedon Feb 6, 2024
@ST-DDT This is great! Are you planning to open a pull request?
ST-DDT commentedon Feb 6, 2024
Sadly, I can currently only answer that with "maybe".
We are about to wrap up development for v8.x (today) and start with v9.
For that we have some improvements planned that will likely also affect the implementation of password method (same as all other methods), so this might change in implementation, but not much in API.
Which feature is added by the branch, that you would like to use that is not possible with the current one?
Maybe we can recommend a workaround until then?
FFR: https://fakerjs.dev/api/internet.html#password
matthewmayer commentedon Sep 17, 2025
If we do decide to go ahead with this it might be useful to review the passwordrules HTML attribute used by safari
https://developer.apple.com/documentation/security/customizing-password-autofill-rules
Although it doesn't seem to have much adoption it does cover most of the typical password rules that sites request.
gruhn commentedon Sep 23, 2025
Hey guys, I'm building a library that can compute regex "intersections". Maybe that could be useful here. All these independent password constraints can easily be expressed with individual regex:
/[0-9]//[A-Z]//^\w{12,}$/It's much harder to write that with a single regex. But that's what regex intersections can do. With that you can turn multiple independent regex into a single one that exactly matches the intersection of all input regex. Once you have a single regex it should™ be easy to generate matching strings. Here is how the API looks like:
A downside is that the generated regex can be very large at the moment. I tried to do:
but I get a call stack overflow. It works with some other libraries though, which generate strings from regex. So this approach is definitely possible. I'm also trying to add my own generator to the library. That one has the luxury of skipping the "serialization" into a native JavaScript regex and instead generate strings directly from an internal representation:
Looks promising at first sight but it sometimes looks like strings are "biased" in way I don't really understand right now.
Anyway, make of that what you want. Maybe some interesting inspiration 🙂