From 15c2189f073f70867d5cac53443bebf8bff8a7c0 Mon Sep 17 00:00:00 2001 From: lijiarao Date: Wed, 6 Dec 2023 15:28:47 +0800 Subject: [PATCH] =?UTF-8?q?rollback=20=E7=99=BB=E5=BD=95=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/impl/LoginServiceImpl.java | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/laws-module-system/src/main/java/com/jero/modules/system/service/impl/LoginServiceImpl.java b/laws-module-system/src/main/java/com/jero/modules/system/service/impl/LoginServiceImpl.java index 6c4e2c57..5c53b2ff 100644 --- a/laws-module-system/src/main/java/com/jero/modules/system/service/impl/LoginServiceImpl.java +++ b/laws-module-system/src/main/java/com/jero/modules/system/service/impl/LoginServiceImpl.java @@ -1,6 +1,7 @@ package com.jero.modules.system.service.impl; import cn.hutool.core.util.RandomUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.asymmetric.RSA; import com.alibaba.fastjson.JSONObject; import com.aliyuncs.exceptions.ClientException; @@ -94,22 +95,22 @@ public class LoginServiceImpl implements ILoginService { String rsaPublicKey = sysLoginModel.getRsaPublicKey(); String rsaPrivateKey = redisUtil.get(rsaPublicKey) != null ? String.valueOf(redisUtil.get(rsaPublicKey)) : null; - //if(StrUtil.isEmpty(rsaPrivateKey)){ - // return Result.error(CommonConstant.SC_RSA_TIMEOUT_600, "页面过期,将刷新页面"); - //} + if(StrUtil.isEmpty(rsaPrivateKey)){ + return Result.error(CommonConstant.SC_RSA_TIMEOUT_600, "页面过期,将刷新页面"); + } - //String captcha = sysLoginModel.getCaptcha(); - //if(captcha==null){ - // return Result.error("验证码无效"); - //} - //String lowerCaseCaptcha = captcha.toLowerCase(); - //String realKey = MD5Util.MD5Encode(lowerCaseCaptcha + sysLoginModel.getCheckKey(), UTF_8); - //Object checkCode = redisUtil.get(realKey); - //// 验证码前后端比较 - //if(checkCode == null || !checkCode.toString().equals(lowerCaseCaptcha)) { - // return Result.error("验证码错误"); - //} - //redisUtil.del(realKey); + String captcha = sysLoginModel.getCaptcha(); + if(captcha==null){ + return Result.error("验证码无效"); + } + String lowerCaseCaptcha = captcha.toLowerCase(); + String realKey = MD5Util.MD5Encode(lowerCaseCaptcha + sysLoginModel.getCheckKey(), UTF_8); + Object checkCode = redisUtil.get(realKey); + // 验证码前后端比较 + if(checkCode == null || !checkCode.toString().equals(lowerCaseCaptcha)) { + return Result.error("验证码错误"); + } + redisUtil.del(realKey); try { //解密获取密码和用户名 password = CommonUtils.decryptBtRsaPriKey(password, rsaPrivateKey); @@ -138,15 +139,15 @@ public class LoginServiceImpl implements ILoginService { return Result.error("密码错误次数过多,请15分钟后重试"); } //2. 校验用户名或密码是否正确 - //String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt()); - //String syspassword = sysUser.getPassword(); - //if (!syspassword.equals(userpassword)) { - // // 重试登录次数加一 - // retryCount++; - // this.setRetryInfoToRedis(username, retryCount); - // String msg = retryCount == RETRY_LOGIN_MAX_COUNT ? "密码错误次数过多,请稍后重试":"用户名或密码错误,剩余可登录次数:"+(RETRY_LOGIN_MAX_COUNT - retryCount); - // return Result.error(msg); - //} + String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt()); + String syspassword = sysUser.getPassword(); + if (!syspassword.equals(userpassword)) { + // 重试登录次数加一 + retryCount++; + this.setRetryInfoToRedis(username, retryCount); + String msg = retryCount == RETRY_LOGIN_MAX_COUNT ? "密码错误次数过多,请稍后重试":"用户名或密码错误,剩余可登录次数:"+(RETRY_LOGIN_MAX_COUNT - retryCount); + return Result.error(msg); + } //登录成功,清除错误登录次数 redisUtil.del(RETRY_LOGIN_PREFIX + username); if (checkSysPermission(username)) {