- Passay Tutorial
- Passay − Home
- Passay − Overview
- Passay − environment Setup
- Validation/Generation
- Passay − Password Validation
- Passay − Customized Messages
- Passay − M of N Rules
- Passay − Password Generation
- Positive Matching Rules
- passay − AllowedCharacterRule
- Passay − AllowedRegexRule
- Passay −CharacterRule
- passay − LengthRule
- Passay − CharacterCharacteristicsRule
- Passay − LengthComplexityRule
- Negative Matching Rules
- Passay − lllegalCharacterRule
- Passay − NumberRangeRule
- Passay − WhitespaceRule
- Passay − DictionaryRule
- Passay − DictionarySubstringRule
- Passay − HistoryRule
- passay − RepeatCharacterRegexRule
- Passay − usernameRule
- Passay Useful Resources
- Passay - Quick Guide
- Passay - Resources
- Passay - Discussion
Passay - DictionarySubstringRule
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.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" })); DictionarySubstringRule dictionaryRule = new DictionarySubstringRule(wordListDictionary); PasswordValidator validator = new PasswordValidator(dictionaryRule); PasswordData password = new PasswordData("password@123"); 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 contains the dictionary word 'password'.]
Advertisements
To Continue Learning Please Login
Login with Google