When the username is username4 and the password is usernameWithPassword, the UsernameRule will return true since it cannot detect a substring of the username.
To address this issue, a new rule called UsernameSubstringRule can be implemented, following a similar approach as the DictionarySubstringRule. The following is an example implementation of this rule in Kotlin:
class UsernameSubstringRule : DictionarySubstringRule() {
override fun validate(passwordData: PasswordData): RuleResult {
val minimumSubstringLength = minOf(5, passwordData.username.length)
dictionary = object : Dictionary {
override fun search(word: String): Boolean {
if (word.length < minimumSubstringLength) {
return false
}
return passwordData.username.lowercase().contains(word.lowercase())
}
override fun size(): Long {
return 1
}
}
return super.validate(passwordData)
}
}
Please note that I did not consider efficiency or any other factors. Kindly confirm if this approach is acceptable before I proceed to write the code in Java and submit a merge request.
When the username is
username4
and the password isusernameWithPassword
, theUsernameRule
will returntrue
since it cannot detect a substring of the username.To address this issue, a new rule called
UsernameSubstringRule
can be implemented, following a similar approach as theDictionarySubstringRule
. The following is an example implementation of this rule in Kotlin:Please note that I did not consider efficiency or any other factors. Kindly confirm if this approach is acceptable before I proceed to write the code in Java and submit a merge request.