📅  最后修改于: 2023-12-03 15:18:16.376000             🧑  作者: Mango
Passay-DictionarySubstringRule是一个Passay密码校验规则,可以用于检查密码是否包含字典中的子字符串。Passay是一个密码策略库,它提供了很多密码验证规则和密码生成工具。
代码示例:
// create a dictionary instance
Dictionary dictionary = new WordListDictionary(new ArrayWordList(new String[]{"password", "qwerty", "123456"}));
// create the rule and add the dictionary
PasswordValidator validator = new PasswordValidator(new DictionarySubstringRule(dictionary));
// validate passwords
RuleResult result = validator.validate(new PasswordData("password123"));
if(result.isValid()) {
System.out.println("Password is valid");
} else {
System.out.println("Password is invalid: " + result.getDetails().toString());
}
代码示例:
// create a dictionary instance
Dictionary dictionary = new WordListDictionary(new ArrayWordList(new String[]{"password", "qwerty", "123456"}));
// create the rule and add the dictionary with minimum and maximum substring lengths
PasswordValidator validator = new PasswordValidator(new DictionarySubstringRule(dictionary, 3, 6));
// validate passwords
RuleResult result = validator.validate(new PasswordData("password123"));
if(result.isValid()) {
System.out.println("Password is valid");
} else {
System.out.println("Password is invalid: " + result.getDetails().toString());
}
<dependency>
<groupId>org.passay</groupId>
<artifactId>passay</artifactId>
<version>1.6.0</version>
</dependency>
Passay-DictionarySubstringRule提供了一种简单但有效的方式来检查密码是否包含字典中的子字符串。它可以很容易地与Passay密码校验框架集成,是一个比较常用的密码校验规则。