Class CharacterRule

java.lang.Object
org.passay.rule.CharacterRule
All Implemented Interfaces:
Rule

public class CharacterRule extends Object implements Rule
Validates whether a password contains a certain number of a type of character.
  • Field Details

    • characterData

      protected final CharacterData characterData
      Character data for this rule.
    • numCharacters

      protected final int numCharacters
      Number of characters to require. Default value is 1.
  • Constructor Details

    • CharacterRule

      public CharacterRule(CharacterData data)
      Creates a new character rule.
      Parameters:
      data - character data for this rule
    • CharacterRule

      public CharacterRule(CharacterData data, int num)
      Creates a new character rule.
      Parameters:
      data - character data for this rule
      num - 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

      public CharacterData getCharacterData()
      Returns the character data for this rule.
      Returns:
      character data
    • getValidCharacters

      public String getValidCharacters()
      Returns the characters that are considered valid for this rule.
      Returns:
      valid characters
    • validate

      public RuleResult validate(PasswordData passwordData)
      Description copied from interface: Rule
      Validates the supplied password data per the requirements of this rule.
      Specified by:
      validate in interface Rule
      Parameters:
      passwordData - to verify (not null).
      Returns:
      details on password verification
    • createRuleResultDetailParameters

      protected Map<String,Object> createRuleResultDetailParameters(String matchingChars)
      Creates the parameter data for the rule result detail.
      Parameters:
      matchingChars - characters found in the password
      Returns:
      map of parameter name to value
    • createRuleResultMetadata

      protected RuleResultMetadata createRuleResultMetadata(PasswordData password)
      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 match
      input - to search for matches
      maximumLength - maximum length of matching characters
      Returns:
      matching characters or empty string
    • toString

      public String toString()
      Overrides:
      toString in class Object