- 帕賽教程
- 帕賽 − 首頁
- 帕賽 − 概述
- 帕賽 − 環境設定
- 驗證/生成
- 帕賽 − 密碼驗證
- 帕賽 − 自定義訊息
- 帕賽 −M of N 規則
- 帕賽 − 密碼生成
- 正向匹配規則
- passay − AllowedCharacterRule
- 帕賽 − AllowedRegexRule
- 帕賽 − CharacterRule
- passay − LengthRule
- 帕賽 − CharacterCharacteristicsRule
- 帕賽 − LengthComplexityRule
- 反向匹配規則
- 帕賽 − lllegalCharacterRule
- 帕賽 − NumberRangeRule
- 帕賽 − WhitespaceRule
- 帕賽 − DictionaryRule
- 帕賽 − DictionarySubstringRule
- 帕賽 − HistoryRule
- passay − RepeatCharacterRegexRule
- 帕賽 − usernameRule
- 帕賽實用資源
- 帕賽 - 快速指南
- 帕賽 - 資源
- 帕賽 - 討論
帕賽 - IllegalCharacterRule
IllegalCharacterRule 允許指定密碼中不允許出現的字元。考慮以下示例。
示例
import org.passay.IllegalCharacterRule;
import org.passay.NumberRangeRule;
import org.passay.PasswordData;
import org.passay.PasswordValidator;
import org.passay.RuleResult;
import org.passay.WhitespaceRule;
public class PassayExample {
public static void main(String[] args) {
//Rule: Special characters like &, <, > are not allowed in a password
IllegalCharacterRule illegalCharacterRule
= new IllegalCharacterRule(new char[] {'&', '<', '>'});
//Rule: 1 to 5 numbers are not allowed
NumberRangeRule numberRangeRule = new NumberRangeRule(1, 5);
//Rule: White spaces are not allowed
WhitespaceRule whitespaceRule = new WhitespaceRule();
PasswordValidator validator
= new PasswordValidator(illegalCharacterRule,numberRangeRule,whitespaceRule);
PasswordData password = new PasswordData("abc&4d ef6");
RuleResult result = validator.validate(password);
if(result.isValid()){
System.out.println("Password validated.");
}else{
System.out.println("Invalid Password: " + validator.getMessages(result));
}
}
}
輸出
Invalid Password: [ Password contains the illegal character '&'., Password contains the number '4'., Password contains a whitespace character.]
廣告