Package org.passay

Class 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.
    Author:
    Middleware Services
    • Field Detail

      • characterData

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

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

      • 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 Detail

      • setNumberOfCharacters

        public void setNumberOfCharacters​(int n)
        Sets the number of characters to require in a password.
        Parameters:
        n - number of characters to require where n > 0
      • 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