Class LengthComplexityRule

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

public class LengthComplexityRule extends Object implements Rule
Rule for determining if a password contains the desired complexity for a certain length. In order to meet the criteria of this rule, passwords must meet all the supplied rules for a given password length.
  • Field Details

    • ERROR_CODE

      public static final String ERROR_CODE
      Error code for insufficient complexity.
      See Also:
    • ERROR_CODE_RULES

      public static final String ERROR_CODE_RULES
      Error code for missing complexity rules.
      See Also:
    • rules

      private final Map<LengthComplexityRule.Interval,List<Rule>> rules
      Rules to apply when checking a password.
    • reportFailure

      private final boolean reportFailure
      Whether to report the details of this rule failure.
    • reportRuleFailures

      private final boolean reportRuleFailures
      Whether to report the details of each complexity rule failure.
  • Constructor Details

    • LengthComplexityRule

      public LengthComplexityRule(LengthComplexityRule.Entry... intervals)
      Creates a new length complexity rule.
      Parameters:
      intervals - interval string to rules
    • LengthComplexityRule

      public LengthComplexityRule(Collection<LengthComplexityRule.Entry> intervals)
      Creates a new length complexity rule.
      Parameters:
      intervals - interval string to rules
    • LengthComplexityRule

      public LengthComplexityRule(boolean reportFailure, boolean reportRuleFailures, LengthComplexityRule.Entry... intervals)
      Creates a new length complexity rule.
      Parameters:
      reportFailure - whether to report failures
      reportRuleFailures - whether to report rule failures
      intervals - interval string to rules
    • LengthComplexityRule

      public LengthComplexityRule(boolean reportFailure, boolean reportRuleFailures, Collection<LengthComplexityRule.Entry> intervals)
      Creates a new length complexity rule.
      Parameters:
      reportFailure - whether to report failures
      reportRuleFailures - whether to report rule failures
      intervals - interval string to rules
  • Method Details

    • getReportFailure

      public boolean getReportFailure()
      Returns whether to add the rule result detail of this rule to the rule result.
      Returns:
      whether to add rule result detail of this rule
    • getReportRuleFailures

      public boolean getReportRuleFailures()
      Returns whether to add the rule result detail for each rule that fails to validate to the rule result.
      Returns:
      whether to add rule result details
    • getRules

      public Map<LengthComplexityRule.Interval,List<? extends Rule>> getRules()
      Returns the password rules for this complexity rule.
      Returns:
      unmodifiable map of password rules
    • 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
    • getRulesByLength

      private List<Rule> getRulesByLength(int length)
      Returns the rules that apply to the supplied password length.
      Parameters:
      length - of the password
      Returns:
      rules or null if length is not included in any interval
    • createRuleResultDetailParameters

      protected Map<String,Object> createRuleResultDetailParameters(int length, int success, int ruleCount)
      Creates the parameter data for the rule result detail.
      Parameters:
      length - of the password
      success - number of successful rules
      ruleCount - number of total rules
      Returns:
      map of parameter name to value
    • toString

      public String toString()
      Overrides:
      toString in class Object