Class UsernameRule

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

public class UsernameRule extends Object implements Rule
Rule for determining if a password contains the username associated with that password. This rule returns true if a supplied PasswordData returns a null or empty username.
  • Field Details

    • ERROR_CODE

      public static final String ERROR_CODE
      Error code for matching username.
      See Also:
    • ERROR_CODE_REVERSED

      public static final String ERROR_CODE_REVERSED
      Error code for matching reversed dictionary word.
      See Also:
    • matchBackwards

      private final boolean matchBackwards
      Whether to search for username backwards.
    • ignoreCase

      private final boolean ignoreCase
      Whether to ignore case when checking for usernames.
    • matchBehavior

      private final MatchBehavior matchBehavior
      Where to match username.
  • Constructor Details

    • UsernameRule

      public UsernameRule()
      Default constructor.
    • UsernameRule

      public UsernameRule(MatchBehavior behavior)
      Create a new username rule.
      Parameters:
      behavior - how to match username
    • UsernameRule

      public UsernameRule(boolean matchBackwards, boolean ignoreCase)
      Create a new username rule.
      Parameters:
      matchBackwards - whether to match backwards
      ignoreCase - whether to ignore case
    • UsernameRule

      public UsernameRule(boolean matchBackwards, boolean ignoreCase, MatchBehavior behavior)
      Create a new username rule.
      Parameters:
      matchBackwards - whether to match backwards
      ignoreCase - whether to ignore case
      behavior - how to match username
  • Method Details

    • isMatchBackwards

      public boolean isMatchBackwards()
      Returns whether to match the username backwards.
      Returns:
      whether to match username backwards
    • isIgnoreCase

      public boolean isIgnoreCase()
      Returns whether to ignore the case of the username.
      Returns:
      whether to ignore case
    • getMatchBehavior

      public MatchBehavior getMatchBehavior()
      Returns the match behavior for this rule.
      Returns:
      match behavior
    • 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(CharSequence username)
      Creates the parameter data for the rule result detail.
      Parameters:
      username - matching username
      Returns:
      map of parameter name to value
    • toString

      public String toString()
      Overrides:
      toString in class Object