优化登录限制的提示

This commit is contained in:
none 2023-07-03 17:41:44 +08:00
parent c987b34b9b
commit a23155cb27
3 changed files with 9 additions and 5 deletions

View File

@ -63,7 +63,9 @@ public class LoginController {
String limitKey = "admin-login-limit:" + loginRequest.getEmail(); String limitKey = "admin-login-limit:" + loginRequest.getEmail();
Long reqCount = rateLimiterService.current(limitKey, 3600L); Long reqCount = rateLimiterService.current(limitKey, 3600L);
if (reqCount > 5) { if (reqCount > 5) {
return JsonResponse.error("多次账密错误账号被锁1个小时"); Long exp = RedisUtil.ttl(limitKey);
return JsonResponse.error(
String.format("您的账号已被锁定,请%s后重试", exp > 60 ? exp / 60 + "分钟" : exp + ""));
} }
String password = String password =

View File

@ -65,7 +65,9 @@ public class LoginController {
String limitKey = "login-limit:" + req.getEmail(); String limitKey = "login-limit:" + req.getEmail();
Long reqCount = rateLimiterService.current(limitKey, 600L); Long reqCount = rateLimiterService.current(limitKey, 600L);
if (reqCount >= 10) { if (reqCount >= 10) {
return JsonResponse.error("多次账密错误账号被锁10分钟"); Long exp = RedisUtil.ttl(limitKey);
return JsonResponse.error(
String.format("您的账号已被锁定,请%s后重试", exp > 60 ? exp / 60 + "分钟" : exp + ""));
} }
if (!HelperUtil.MD5(req.getPassword() + user.getSalt()).equals(user.getPassword())) { if (!HelperUtil.MD5(req.getPassword() + user.getSalt()).equals(user.getPassword())) {

View File

@ -26,12 +26,12 @@ import java.util.HashMap;
@Service @Service
public class BackendAuthServiceImpl implements BackendAuthService { public class BackendAuthServiceImpl implements BackendAuthService {
@Autowired @Autowired private AuthService authService;
private AuthService authService;
@Override @Override
public String loginUsingId(Integer userId, String loginUrl) { public String loginUsingId(Integer userId, String loginUrl) {
return authService.loginUsingId(100000000 + userId, loginUrl, SystemConstant.JWT_PRV_ADMIN_USER); return authService.loginUsingId(
100000000 + userId, loginUrl, SystemConstant.JWT_PRV_ADMIN_USER);
} }
@Override @Override