- 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 classPasswordChecker.FactoryInternal factory to createPasswordCheckers.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PasswordCheckStatuscheck(String password)Check if a password can be validated against the specified criteria and return the first error encountered if any orPasswordCheckStatus.OKotherwise.static PasswordChecker.Factoryfactory()Create a factory to specify password validation criteria and create aPasswordCheckerobject.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.StringgetAllChars()Return all characters used in generating password.StringgetCharacterGroup(int index)Return the nth character group used in creating passwords.intgetCharacterGroupCount()Returns how many character groups are used in composing passwords.List<String>getCharacterGroups()Returns a list of the character groups composing the generated passwords.intgetMaxCharactersInGroup(int index)Return the maximum number of characters from the nth character group allowed in generated passwords.intgetMaxLength()Get the maximum length required for a password to be accepted.intgetMinCharactersInGroup(int index)Return how many characters from the nth character group are required in generated passwords.intgetMinLength()Get the minimum length required for a password to be accepted.booleanquickCheck(String password)Check if a password can be validated against the specified criteria and returntrueif that's the case.
-
-
-
Method Detail
-
factory
public static PasswordChecker.Factory factory()
Create a factory to specify password validation criteria and create aPasswordCheckerobject.- Returns:
- an internal
PasswordCheckerfactory - See Also:
PasswordChecker.Factory
-
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 returntrueif that's the case.- Parameters:
password- to be validated- Returns:
trueifpasswordmatches 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 orPasswordCheckStatus.OKotherwise.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.OKifpasswordmatches the criteria, otherwise a code for the first error encountered- See Also:
PasswordCheckStatus
-
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
passwordmatches all the criteria - See Also:
PasswordCheckError
-
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 is0(zero).- Parameters:
index- of the character group to retrieve- Returns:
- the character group at the
index - Throws:
IndexOutOfBoundsException- if theindexis 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 is0(zero).- Parameters:
index- of the character group minimum count to retrieve- Returns:
- the minimum number of characters from the group at the
indexrequired to form a valid password - Throws:
IndexOutOfBoundsException- if theindexis 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 is0(zero).- Parameters:
index- of the character group maximum count to retrieve- Returns:
- the maximum number of characters from the group at the
indexallowed in a valid password - Throws:
IndexOutOfBoundsException- if theindexis invalid
-
getAllChars
public String getAllChars()
Return all characters used in generating password.- Returns:
- characters used in generating password
-
-