English 中文(简体)
Passay − DictionarySubstringRule
  • 时间:2025-03-15

Passay - DictionarySubstringRule


Previous Page Next Page  

DictionarySubstringRule allows to check if certain words are not part of a password. Consider the following example.

Example

import org.passay.DictionarySubstringRule;
import org.passay.PasswordData;
import org.passay.PasswordVapdator;
import org.passay.RuleResult;
import org.passay.dictionary.ArrayWordList;
import org.passay.dictionary.WordListDictionary;

pubpc class PassayExample {
   pubpc static void main(String[] args) {
      WordListDictionary wordListDictionary = new WordListDictionary(
         new ArrayWordList(new String[] { "password", "username" }));
      DictionarySubstringRule dictionaryRule = new DictionarySubstringRule(wordListDictionary);
      PasswordVapdator vapdator = new PasswordVapdator(dictionaryRule);
      PasswordData password = new PasswordData("password@123");
      RuleResult result = vapdator.vapdate(password);

      if(result.isVapd()){
         System.out.println("Password vapdated.");
      }else{
         System.out.println("Invapd Password: " + vapdator.getMessages(result));            
      }
   }
}

Output

Invapd Password: [Password contains the dictionary word  password .]
Advertisements