Class LengthRule

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

public class LengthRule extends Object implements Rule
Rule for determining if a password is within a desired length. The minimum and maximum lengths are used inclusively to determine if a password meets this rule.
  • Field Details

    • ERROR_CODE_MIN

      public static final String ERROR_CODE_MIN
      Error code for password too short.
      See Also:
    • ERROR_CODE_MAX

      public static final String ERROR_CODE_MAX
      Error code for password too long.
      See Also:
    • minimumLength

      private final int minimumLength
      Stores the minimum length of a password.
    • maximumLength

      private final int maximumLength
      Stores the maximum length of a password.
  • Constructor Details

    • LengthRule

      public LengthRule()
      Creates a new length rule with lengths unset. The defaults are 0 and Integer.MAX_VALUE respectively.
    • LengthRule

      public LengthRule(int length)
      Creates a new length rule with the supplied length. Both the minimum and the maximum length will be set to this value.
      Parameters:
      length - length of password
    • LengthRule

      public LengthRule(int minLength, int maxLength)
      Create a new length rule.
      Parameters:
      minLength - minimum length of a password
      maxLength - maximum length of a password
  • Method Details

    • getMinimumLength

      public int getMinimumLength()
      Returns the minimum password length.
      Returns:
      minimum password length
    • getMaximumLength

      public int getMaximumLength()
      Returns the maximum password length.
      Returns:
      maximum length of a password
    • 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()
      Creates the parameter data for the rule result detail.
      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
    • toString

      public String toString()
      Overrides:
      toString in class Object