How to match part of username with password with Passay library?

I would like to combine the username part with the password with the passay library, for example:
Username: " jhon .smith" and password: "123 jhon "

I found a UsernameRule that only controls the username in the password, for example: " MyUser " and " MyUser password".
p>

+3


source to share


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







All Articles