From 842947e6ecf0bdf8fd98049c0e47eb3893a8cbdb Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期三, 25 九月 2024 18:13:14 +0800 Subject: [PATCH] 修改接口 --- ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 48 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..208be4a 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,60 @@ 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("111111"); + System.err.println(s); + boolean b = SecurityUtils.matchesPassword("111111", "$2a$10$Wx75W2oW23.tsSkvA21QyueQ59iwWwv2ns06Bxubje0ZwPe2wNOQ2"); + System.err.println(b); + } + public boolean reMatches(SysUser user, String rawPassword) + { + return SecurityUtils.matchesPassword(rawPassword, user.getRePassword()); + } + public void clearLoginRecordCache(String loginName) { if (redisCache.hasKey(getCacheKey(loginName))) -- Gitblit v1.7.1