add 配置文件增加是否需要密码配置

This commit is contained in:
lijiarao
2023-08-24 10:57:42 +08:00
parent 6ac6da4613
commit 420faa8dea
5 changed files with 123 additions and 93 deletions
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.exceptions.ClientException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jero.common.exception.JeroBootException;
import com.jero.config.StaticConfig;
import com.jero.modules.system.entity.*;
import com.jero.modules.system.model.SysLoginVO;
import com.jero.modules.system.service.*;
@@ -93,21 +94,24 @@ public class LoginController {
//password = AesEncryptUtil.desEncrypt(sysLoginModel.getPassword().replaceAll("%2B", "\\+")).trim();//密码解密
//update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题
//update-begin-author:taoyan date:20190828 for:校验验证码
String captcha = sysLoginModel.getCaptcha();
if (captcha == null) {
result.error500("验证码无效");
return result;
}
String lowerCaseCaptcha = captcha.toLowerCase();
String realKey = MD5Util.MD5Encode(lowerCaseCaptcha + sysLoginModel.getCheckKey(), "utf-8");
Object checkCode = redisUtil.get(realKey);
//当进入登录页时,有一定几率出现验证码错误 #1714
if (checkCode == null || !checkCode.toString().equals(lowerCaseCaptcha)) {
result.error500("验证码错误");
return result;
} else {
redisUtil.del(realKey);
if (StaticConfig.needPassword){
String captcha = sysLoginModel.getCaptcha();
if (captcha == null) {
result.error500("验证码无效");
return result;
}
String lowerCaseCaptcha = captcha.toLowerCase();
String realKey = MD5Util.MD5Encode(lowerCaseCaptcha + sysLoginModel.getCheckKey(), "utf-8");
Object checkCode = redisUtil.get(realKey);
//当进入登录页时,有一定几率出现验证码错误 #1714
if (checkCode == null || !checkCode.toString().equals(lowerCaseCaptcha)) {
result.error500("验证码错误");
return result;
} else {
redisUtil.del(realKey);
}
}
try {
//解密获取密码和用户名
password = CommonUtils.decryptBtRsaPriKey(password, rsaPrivateKey);
@@ -136,21 +140,24 @@ public class LoginController {
result.error500("密码错误次数过多,请"+passwordResetTime+"分钟后重试");
return result;
}
//2. 校验用户名或密码是否正确
String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt());
String syspassword = sysUser.getPassword();
if (!syspassword.equals(userpassword)) {
// 重试登录次数加一
retryCount++;
if (retryCount == 1) {
redisUtil.set(RETRY_LOGIN_PREFIX + username, retryCount, 60 * passwordResetTime);
} else {
redisUtil.set(RETRY_LOGIN_PREFIX + username, retryCount, redisUtil.getExpire(RETRY_LOGIN_PREFIX + username));
if (StaticConfig.needPassword){
//2. 校验用户名或密码是否正确
String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt());
String syspassword = sysUser.getPassword();
if (!syspassword.equals(userpassword)) {
// 重试登录次数加一
retryCount++;
if (retryCount == 1) {
redisUtil.set(RETRY_LOGIN_PREFIX + username, retryCount, 60 * passwordResetTime);
} else {
redisUtil.set(RETRY_LOGIN_PREFIX + username, retryCount, redisUtil.getExpire(RETRY_LOGIN_PREFIX + username));
}
String msg = retryCount == RETRY_LOGIN_MAX_COUNT ? "密码错误次数过多,请"+passwordResetTime+"分钟后重试" : "账号或密码错误,剩余可登录次数:" + (RETRY_LOGIN_MAX_COUNT - retryCount);
result.error500(msg);
return result;
}
String msg = retryCount == RETRY_LOGIN_MAX_COUNT ? "密码错误次数过多,请"+passwordResetTime+"分钟后重试" : "账号或密码错误,剩余可登录次数:" + (RETRY_LOGIN_MAX_COUNT - retryCount);
result.error500(msg);
return result;
}
//登录成功,清除错误登录次数
redisUtil.del(RETRY_LOGIN_PREFIX + username);
//如果用初始密码登录,前端就跳转到修改密码界面