Passay - กฎพจนานุกรม

DictionaryRuleอนุญาตให้ตรวจสอบว่าคำบางคำไม่ได้ระบุเป็นรหัสผ่านหรือไม่ ลองพิจารณาตัวอย่างต่อไปนี้

ตัวอย่าง

import org.passay.DictionaryRule;
import org.passay.PasswordData;
import org.passay.PasswordValidator;
import org.passay.RuleResult;
import org.passay.dictionary.ArrayWordList;
import org.passay.dictionary.WordListDictionary;

public class PassayExample {
   public static void main(String[] args) {
      WordListDictionary wordListDictionary = new WordListDictionary(
         new ArrayWordList(new String[] { "password", "username" }));
      DictionaryRule dictionaryRule = new DictionaryRule(wordListDictionary);
      PasswordValidator validator = new PasswordValidator(dictionaryRule);
      PasswordData password = new PasswordData("password");
      RuleResult result = validator.validate(password);

      if(result.isValid()){
         System.out.println("Password validated.");
      }else{
         System.out.println("Invalid Password: " + validator.getMessages(result));            
      }
   }
}

เอาต์พุต

Invalid Password: [Password contains the dictionary word 'password'.]