Class PasswordGenerator

java.lang.Object
org.panteleyev.commons.password.PasswordGenerator

public final class PasswordGenerator extends Object
Implements password generation functionality.

The following characters are considered ambiguous from visual standpoint: I l O. They are excluded by default and can be included with generate(Set, int, boolean).

Password length must be greater than 4 in order to ensure all specified character sets can be present in the generated string. There is no upper limit for password length.

Instances of this class are thread safe and can be reused.

  • Constructor Details

    • PasswordGenerator

      public PasswordGenerator()
  • Method Details

    • generate

      public String generate(Set<PasswordCharacterSet> characterSets, int length)
      Generates password and avoids ambiguous letters.
      Parameters:
      characterSets - password character sets
      length - password length
      Returns:
      password
      Throws:
      IllegalArgumentException - if no character sets are selected or password length < 4
    • generate

      public String generate(Set<PasswordCharacterSet> characterSets, int length, boolean allowAmbiguousLetters)
      Generates password.
      Parameters:
      characterSets - password character sets
      length - password length
      allowAmbiguousLetters - true if set of ambiguous letters should be included
      Returns:
      password
      Throws:
      IllegalArgumentException - if no character sets are selected or password length < 4