Passay Tutorial on Passay RepeatCharacterRegexRule

repeatcharacterregexrule allows to check if given password has repeated ascii characters. consider the following example.

example

import org.passay.lengthrule;
import org.passay.passworddata;
import org.passay.passwordvalidator;
import org.passay.repeatcharacterregexrule;
import org.passay.rule;
import org.passay.ruleresult;

public class passayexample {
   public static void main(string[] args) {
      //rule: password should not contain repeated entries
      rule rule1 = new repeatcharacterregexrule(3);
      //8 and 16 characters
      rule rule2 = new lengthrule(8, 16);    

      passwordvalidator validator = new passwordvalidator(rule1, rule2);
      passworddata password = new passworddata("aaefhehhhhh");
      ruleresult result = validator.validate(password);

      if(result.isvalid()){
         system.out.println("password validated.");
      }else{
         system.out.println("invalid password: " + validator.getmessages(result));            
      }
   }
}

output

invalid password: [password matches the illegal pattern 'hhh'.]