From feb55df0dd6b31d160f9475873a413d01a96866d Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期四, 14 十一月 2024 10:17:02 +0800
Subject: [PATCH] 修改

---
 ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java
index 6ad91b0..c1f7676 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java
@@ -78,12 +78,63 @@
             clearLoginRecordCache(username);
         }
     }
+    public void reValidate(SysUser user)
+    {
+        Authentication usernamePasswordAuthenticationToken = AuthenticationContextHolder.getContext();
+        String username = usernamePasswordAuthenticationToken.getName();
+        if(username.contains("_")){
+            username = username.split("_")[0];
+        }
+        String password = usernamePasswordAuthenticationToken.getCredentials().toString();
+
+        Integer retryCount = redisCache.getCacheObject(getCacheKey(username));
+
+        if (retryCount == null)
+        {
+            retryCount = 0;
+        }
+
+        if (retryCount >= Integer.valueOf(maxRetryCount).intValue())
+        {
+            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL,
+                    MessageUtils.message("user.password.retry.limit.exceed", maxRetryCount, lockTime)));
+            throw new UserPasswordRetryLimitExceedException(maxRetryCount, lockTime);
+        }
+
+        if (!reMatches(user, password))
+        {
+            retryCount = retryCount + 1;
+            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL,
+                    MessageUtils.message("user.password.retry.limit.count", retryCount)));
+            redisCache.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES);
+            throw new UserPasswordNotMatchException();
+        }
+        else
+        {
+            clearLoginRecordCache(username);
+        }
+    }
 
     public boolean matches(SysUser user, String rawPassword)
     {
         return SecurityUtils.matchesPassword(rawPassword, user.getPassword());
     }
 
+    public static void main(String[] args) {
+        // $2a$10$qofXsM/ZKUMqvysvsWBAfOizecqUdAaXPFUYDVxaYYM0FJg6/mOpq
+        String s = SecurityUtils.encryptPassword("123456");
+        System.err.println(s);
+        boolean b = SecurityUtils.matchesPassword("123456", "$2a$10$Wx75W2oW23.tsSkvA21QyueQ59iwWwv2ns06Bxubje0ZwPe2wNOQ2");
+        System.err.println(b);
+    }
+    public boolean reMatches(SysUser user, String rawPassword)
+    {
+        System.err.println(SecurityUtils.matchesPassword(rawPassword, user.getRePassword()));
+        System.err.println(rawPassword);
+        System.err.println(user.getRePassword());
+        return SecurityUtils.matchesPassword(rawPassword, user.getRePassword());
+    }
+
     public void clearLoginRecordCache(String loginName)
     {
         if (redisCache.hasKey(getCacheKey(loginName)))

--
Gitblit v1.7.1