Package org.passay.rule
Class CharacterRule
java.lang.Object
org.passay.rule.CharacterRule
- All Implemented Interfaces:
Rule
Validates whether a password contains a certain number of a type of character.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CharacterDataCharacter data for this rule.protected final intNumber of characters to require. -
Constructor Summary
ConstructorsConstructorDescriptionCharacterRule(CharacterData data) Creates a new character rule.CharacterRule(CharacterData data, int num) Creates a new character rule. -
Method Summary
Modifier and TypeMethodDescriptioncreateRuleResultDetailParameters(String matchingChars) Creates the parameter data for the rule result detail.protected RuleResultMetadatacreateRuleResultMetadata(PasswordData password) Creates the rule result metadata.Returns the character data for this rule.private static StringgetMatchingCharacters(String characters, UnicodeString input, int maximumLength) Returns all the characters in the input string that are also in the characters string.intReturns the number of characters which must exist in order for a password to meet the requirements of this rule.Returns the characters that are considered valid for this rule.toString()validate(PasswordData passwordData) Validates the supplied password data per the requirements of this rule.
-
Field Details
-
characterData
Character data for this rule. -
numCharacters
protected final int numCharactersNumber of characters to require. Default value is 1.
-
-
Constructor Details
-
CharacterRule
Creates a new character rule.- Parameters:
data- character data for this rule
-
CharacterRule
Creates a new character rule.- Parameters:
data- character data for this rulenum- of characters to enforce
-
-
Method Details
-
getNumberOfCharacters
public int getNumberOfCharacters()Returns the number of characters which must exist in order for a password to meet the requirements of this rule.- Returns:
- number of characters to require
-
getCharacterData
Returns the character data for this rule.- Returns:
- character data
-
getValidCharacters
Returns the characters that are considered valid for this rule.- Returns:
- valid characters
-
validate
Description copied from interface:RuleValidates the supplied password data per the requirements of this rule. -
createRuleResultDetailParameters
Creates the parameter data for the rule result detail.- Parameters:
matchingChars- characters found in the password- Returns:
- map of parameter name to value
-
createRuleResultMetadata
Creates the rule result metadata.- Parameters:
password- data used for metadata creation- Returns:
- rule result metadata
-
getMatchingCharacters
private static String getMatchingCharacters(String characters, UnicodeString input, int maximumLength) Returns all the characters in the input string that are also in the characters string.- Parameters:
characters- that contains characters to matchinput- to search for matchesmaximumLength- maximum length of matching characters- Returns:
- matching characters or empty string
-
toString
-