Skip to content

Reimplement internet.password() with more generation options #768

Open

Description

@ST-DDT

Clear and concise description of the problem

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

Activity

  1. added this to the v7 - Next Major milestone on Apr 3, 2022
  2. moved this to Todo in Faker Roadmapon Apr 3, 2022
  3. xDivisionByZerox commented on Jun 2, 2022

    @xDivisionByZerox
    Member

    This looks interesting, I might provide a PR for this in the near future.

  4. xDivisionByZerox commented on Jun 18, 2022

    @xDivisionByZerox
    Member

    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' })?

  5. ST-DDT commented on Jun 18, 2022

    @ST-DDT
    MemberAuthor

    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.

  6. xDivisionByZerox commented on Jun 18, 2022

    @xDivisionByZerox
    Member

    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:

    type PasswordMode = 'secure' | 'memorable' | 'simple';
    
    password(
      opt:
        | PasswordMode
        | {
            mode?: PasswordMode;
          }
        | {
            length?: number;
            includeSymbols?: boolean;
            includeNumbers?: boolean;
            includeLowercaseChars?: boolean;
            includeUppercaseChars?: boolean;
            noSimilarChars?: boolean;
            noDuplicateChars?: boolean;
            noSequentialChars?: boolean;
            bannedChars?: Array<string>;
          }
    ) {
      // implementation
    }
  7. xDivisionByZerox commented on Jun 18, 2022

    @xDivisionByZerox
    Member

    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?

  8. ST-DDT commented on Jun 18, 2022

    @ST-DDT
    MemberAuthor

    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.

  9. xDivisionByZerox commented on Jun 18, 2022

    @xDivisionByZerox
    Member

    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).

  10. xDivisionByZerox commented on Jun 18, 2022

    @xDivisionByZerox
    Member

    Another approach would be to provide a different signature (advanced options only):

    {
      length: number;
      symbol: {
        include: boolean;
        require: boolean;
      };
      number: {
        include: boolean;
        require: boolean;
      };
      lowercase: {
        include: boolean;
        require: boolean;
      };
      uppercase: {
        include: boolean;
        require: boolean;
      };
      noSimilarChars: boolean;
      noDuplicateChars: boolean;
      noSequentialChars: boolean;
      bannedChars?: readonly LiteralUnion<PasswordChar>[];
    }
    

    I really like this, because we can extend each character group with more options. Like a minimal count for example.

  11. 8 remaining items

  12. xDivisionByZerox commented on Mar 28, 2023

    @xDivisionByZerox
    Member

    But faker.string.fromRegExp is not out yet, tho. It's not even in the latest alpha release 🤔

  13. ejcheng commented on Dec 13, 2023

    @ejcheng
    Member

    This looks interesting, I might provide a PR for this in the near future.

    @xDivisionByZerox Are you still willing to work on this?

  14. xDivisionByZerox commented on Dec 13, 2023

    @xDivisionByZerox
    Member

    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.

  15. ST-DDT commented on Dec 13, 2023

    @ST-DDT
    MemberAuthor
  16. ejcheng commented on Dec 13, 2023

    @ejcheng
    Member

    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?

  17. jacobg commented on Feb 6, 2024

    @jacobg

    https://github.com/faker-js/faker/tree/refactor/internet/password

    @ST-DDT This is great! Are you planning to open a pull request?

  18. ST-DDT commented on Feb 6, 2024

    @ST-DDT
    MemberAuthor

    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

  19. matthewmayer commented on Sep 17, 2025

    @matthewmayer
    Contributor

    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.

  20. gruhn commented on Sep 23, 2025

    @gruhn

    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:

    const combinedRegex = RB(/[0-9]/).and(/[A-Z]/).and(/^\w{12,}$/).toRegExp()

    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:

    const combined = RB(/[0-9]/).and(/[A-Z]/).and(/^\w{12,}$/)
    
    for (const str of combined.sample().take(10)) {
      console.log(str)
    }
    fj_lcwzwmq8lDvY
    vla_nvvrjPjkz0
    pujeg_giwy1vbD6n
    xehngj_q3g9kj8KEwv
    qrlfsm_vsxTbzo5F1S
    acbfgokzr5cS
    cfbikuqvHjW3Wg
    omr_kavfjzR6
    rffbvzjkc1u9P
    yqqzietnbb7Wl
    

    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 🙂

  21. added
    breaking changeCannot be merged when next version is not a major release
    on May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

breaking changeCannot be merged when next version is not a major releasec: featureRequest for new featurem: internetSomething is referring to the internet modulep: 1-normalNothing urgents: acceptedAccepted feature / Confirmed bug

Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions