我正在为密码策略编写代码。
政策规定您不能使用已经使用过的相同字母。例如:密码 - 您不能使用密码,因为它有两个 's'
我怎样才能做到这一点?
编辑:
这是我的完整实现:
private static final String PASSWORD_DUPLICATE_CHARACTERS = "^(?:([a-zA-Z])(?!.*\\1))$";
pattern = Pattern.compile(PASSWORD_DUPLICATE_CHARACTERS);
this.checkForDuplicateLetters(LDAPNewUserPassword);
private boolean checkForDuplicateLetters(final String newPassword) throws LDAPException{
LoggingEnt userEnt = new LoggingEnt();
String userid = userEnt.getUseridCode();
boolean foundDuplicate = false;
matcher = pattern.matcher(newPassword);
if (newPassword.matches(PASSWORD_DUPLICATE_LETTERS)){
foundDuplicate = true;
userEnt.setMsg1("Duplicate.");
throw new LDAPException("Invalid password combination for " + userid, LDAPException.INVALID_CREDENTIALS);//BAristo
} else {
userEnt.setMsg1("Your password has been successfully changed.");
}
return matcher.matches();
}