Class PasswordChecker

java.lang.Object
rodeo.password.pgencheck.PasswordChecker

public final class PasswordChecker extends Object
Validate passwords according to predefined criteria.

The following criteria are available:

  • minimum length;
  • maximum length;
  • constraints on characters composing the password:
    • character must belong to a predefined group of characters;
    • minimum and maximum number of characters per group can be specified.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Internal factory to create PasswordCheckers.
  • Method Summary

    Modifier and Type
    Method
    Description
    check(String password)
    Check if a password can be validated against the specified criteria and return the first error encountered if any or PasswordCheckStatus.OK otherwise.
    Create a factory to specify password validation criteria and create a PasswordChecker object.
    fullCheck(String password)
    Check if a password can be validated against the specified criteria and return a list of all the problems encountered.
    Return all characters used in generating password.
    getCharacterGroup(int index)
    Return the nth character group used in creating passwords.
    int
    Returns how many character groups are used in composing passwords.
    Returns a list of the character groups composing the generated passwords.
    int
    Return the maximum number of characters from the nth character group allowed in generated passwords.
    int
    Get the maximum length required for a password to be accepted.
    int
    Return how many characters from the nth character group are required in generated passwords.
    int
    Get the minimum length required for a password to be accepted.
    boolean
    quickCheck(String password)
    Check if a password can be validated against the specified criteria and return true if that's the case.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • factory

      public static PasswordChecker.Factory factory()
      Create a factory to specify password validation criteria and create a PasswordChecker object.
      Returns:
      an internal PasswordChecker factory
      See Also:
    • getMinLength

      public int getMinLength()
      Get the minimum length required for a password to be accepted.
      Returns:
      the minimum length required for a password to be accepted
    • getMaxLength

      public int getMaxLength()
      Get the maximum length required for a password to be accepted.
      Returns:
      the maximum length required for a password to be accepted
    • quickCheck

      public boolean quickCheck(String password)
      Check if a password can be validated against the specified criteria and return true if that's the case.
      Parameters:
      password - to be validated
      Returns:
      true if password matches the criteria, false otherwise
    • check

      public PasswordCheckStatus check(String password)
      Check if a password can be validated against the specified criteria and return the first error encountered if any or PasswordCheckStatus.OK otherwise.

      Criteria are checked in this order:

      • minimum length of password;
      • maximum length of password;
      • illegal characters;
      • not enough characters from a certain group;
      • too many characters form a certain group.
      Parameters:
      password - to be validated
      Returns:
      PasswordCheckStatus.OK if password matches the criteria, otherwise a code for the first error encountered
      See Also:
    • fullCheck

      public List<PasswordCheckError> fullCheck(String password)
      Check if a password can be validated against the specified criteria and return a list of all the problems encountered. This list is empty if there is no error.
      Parameters:
      password - to be validated
      Returns:
      a list of all the errors encountered while validating the password or an empty list if the password matches all the criteria
      See Also:
    • getCharacterGroups

      public List<String> getCharacterGroups()
      Returns a list of the character groups composing the generated passwords.
      Returns:
      the character groups
    • getCharacterGroupCount

      public int getCharacterGroupCount()
      Returns how many character groups are used in composing passwords.
      Returns:
      character group count
    • getCharacterGroup

      public String getCharacterGroup(int index)
      Return the nth character group used in creating passwords. Character groups are referenced in the order they are added to the factory. The first index is 0 (zero).
      Parameters:
      index - of the character group to retrieve
      Returns:
      the character group at the index
      Throws:
      IndexOutOfBoundsException - if the index is invalid
    • getMinCharactersInGroup

      public int getMinCharactersInGroup(int index)
      Return how many characters from the nth character group are required in generated passwords. Character groups are referenced in the order they were added to the factory. The first index is 0 (zero).
      Parameters:
      index - of the character group minimum count to retrieve
      Returns:
      the minimum number of characters from the group at the index required to form a valid password
      Throws:
      IndexOutOfBoundsException - if the index is invalid
    • getMaxCharactersInGroup

      public int getMaxCharactersInGroup(int index)
      Return the maximum number of characters from the nth character group allowed in generated passwords. Character groups are referenced in the order they were added to the factory. The first index is 0 (zero).
      Parameters:
      index - of the character group maximum count to retrieve
      Returns:
      the maximum number of characters from the group at the index allowed in a valid password
      Throws:
      IndexOutOfBoundsException - if the index is invalid
    • getAllChars

      public String getAllChars()
      Return all characters used in generating password.
      Returns:
      characters used in generating password