重置密码
This commit is contained in:
parent
e38c519632
commit
405f8e520d
|
|
@ -1,5 +1,6 @@
|
|||
package com.bonus.system.service.impl;
|
||||
|
||||
import com.bonus.common.core.exception.ServiceException;
|
||||
import com.bonus.common.core.utils.DateUtils;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.security.utils.SecurityUtils;
|
||||
|
|
@ -38,10 +39,7 @@ public class PasswordValidatorServiceImpl implements PasswordValidatorService {
|
|||
}
|
||||
|
||||
// 2. 检查密码字符类型
|
||||
if (!isPasswordCharacterValid(newPassword)) {
|
||||
return AjaxResult.error(getCharacterRequirementErrorMessage());
|
||||
}
|
||||
|
||||
isPasswordCharacterValid(newPassword);
|
||||
// 3. 检查常见弱密码
|
||||
if (containsWeakPassword(newPassword.toLowerCase())) {
|
||||
return AjaxResult.error("密码包含常见的弱密码片段!");
|
||||
|
|
@ -74,20 +72,40 @@ public class PasswordValidatorServiceImpl implements PasswordValidatorService {
|
|||
return password.length() >= systemConfig.getPasswordConfig().getMinLength() && password.length() <= systemConfig.getPasswordConfig().getMaxLength();
|
||||
}
|
||||
|
||||
private boolean isPasswordCharacterValid(String password) {
|
||||
/**
|
||||
* 判断密码是否规范
|
||||
* @param password
|
||||
*/
|
||||
private void isPasswordCharacterValid(String password) {
|
||||
boolean hasUpperCase = false, hasLowerCase = false, hasDigit = false, hasSpecialChar = false;
|
||||
|
||||
for (char c : password.toCharArray()) {
|
||||
if (Character.isUpperCase(c)) hasUpperCase = true;
|
||||
if (Character.isLowerCase(c)) hasLowerCase = true;
|
||||
if (Character.isDigit(c)) hasDigit = true;
|
||||
if ("!@#$%^&*()-_=+[{]};:'\",<.>/?".indexOf(c) >= 0) hasSpecialChar = true;
|
||||
if (Character.isUpperCase(c)) {
|
||||
hasUpperCase = true;
|
||||
}
|
||||
if (Character.isLowerCase(c)) {
|
||||
hasLowerCase = true;
|
||||
}
|
||||
if (Character.isDigit(c)) {
|
||||
hasDigit = true;
|
||||
}
|
||||
if ("!@#$%^&*()-_=+[{]};:'\",<.>/?".indexOf(c) >= 0) {
|
||||
hasSpecialChar = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (systemConfig.getPasswordConfig().isRequireUpperCase() && !hasUpperCase) return false;
|
||||
if (systemConfig.getPasswordConfig().isRequireLowerCase() && !hasLowerCase) return false;
|
||||
if (systemConfig.getPasswordConfig().isRequireDigit() && !hasDigit) return false;
|
||||
return !(systemConfig.getPasswordConfig().isRequireSpecialChar() && !hasSpecialChar);
|
||||
if (systemConfig.getPasswordConfig().isRequireUpperCase() && !hasUpperCase) {
|
||||
throw new ServiceException("新密码必须包含大写字母!");
|
||||
}
|
||||
if (systemConfig.getPasswordConfig().isRequireLowerCase() && !hasLowerCase) {
|
||||
throw new ServiceException("新密码必须包含小写字母!");
|
||||
}
|
||||
if (systemConfig.getPasswordConfig().isRequireDigit() && !hasDigit) {
|
||||
throw new ServiceException("新密码必须包含数字!");
|
||||
}
|
||||
if (systemConfig.getPasswordConfig().isRequireSpecialChar() && !hasSpecialChar) {
|
||||
throw new ServiceException("新密码必须包含特殊字符!");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean containsWeakPassword(String password) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue