How to match part of username with password with Passay library?
1 answer
One way to do this is to add illegal substrings to the dictionary and then use DictionarySubstringRule.
Let's say you want someone to disallow 4 or more consequtive characters from their name in their password:
List<Rules> rules = new ArrayList<rules>();
List<String> snippets = new ArrayList<String>();
// Add all illegal substrings to a dictionary
for (i = 0; i < username.length() - 4; i++) {
snippets.add(username.substring(i, i + 4));
}
Dictionary dict = new WordListDictionary(new ArrayWordList(snippets.toArray(new String[snippets.size()]));
Rule dsr = new DictionarySubstringRule(dict);
rules.add(dsr);
+3
source to share