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