mirror of
https://github.com/ccfish86/sctalk.git
synced 2026-10-29 06:04:07 +08:00
追加登录密码错误次数限制(连续错误6次,半小时内禁止登录),修复手误
This commit is contained in:
@@ -19,6 +19,8 @@ public abstract class RedisKeys {
|
||||
|
||||
/** 用户信息(Map) */
|
||||
public static String USER_INFO = "usr";
|
||||
/** 用户临时信息-密码错误 */
|
||||
public static String USER_LOGIN_FAILD = "ulf";
|
||||
|
||||
/** 用户信息:用户未读 */
|
||||
public static String USER_UNREAD = "unr";
|
||||
|
||||
+16
-6
@@ -5,12 +5,14 @@
|
||||
package com.blt.talk.service.remote.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.HashOperations;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.data.redis.core.ValueOperations;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -64,6 +66,16 @@ public class LoginServiceController implements LoginService {
|
||||
public BaseModel<UserEntity> login(@RequestBody LoginReq param) {
|
||||
|
||||
BaseModel<UserEntity> userRes = new BaseModel<>();
|
||||
String key = RedisKeys.concat(RedisKeys.USER_LOGIN_FAILD, param.getName());
|
||||
ValueOperations<String, String> faildCountOps = redisTemplate.opsForValue();
|
||||
String faildCount = faildCountOps.get(key);
|
||||
int faild = 0;
|
||||
if (!StringUtils.isEmpty(faildCount)) {
|
||||
faild = Integer.parseInt(faildCount);
|
||||
}
|
||||
if (faild > 5) {
|
||||
return userRes.setResult(LoginCmdResult.LOGIN_PASSWORD_LOCK);
|
||||
}
|
||||
|
||||
// 改为:用户名或手机号皆可登录
|
||||
SearchCriteria<IMUser> userSearchCriteria = new SearchCriteria<>();
|
||||
@@ -79,10 +91,6 @@ public class LoginServiceController implements LoginService {
|
||||
|
||||
IMUser user = users.get(0);
|
||||
|
||||
// if (user.getStatus() == 0) {
|
||||
// 判断用户状态
|
||||
// }
|
||||
|
||||
if (passwordEncoder.matches(param.getPassword(), user.getPassword())) {
|
||||
// 密码正确
|
||||
UserEntity userEntity = new UserEntity();
|
||||
@@ -103,11 +111,13 @@ public class LoginServiceController implements LoginService {
|
||||
userRes.setData(userEntity);
|
||||
|
||||
// 如果登陆成功,则清除错误尝试限制
|
||||
|
||||
if (faild > 0) {
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
} else {
|
||||
|
||||
// 密码错误,记录一次登陆失败
|
||||
|
||||
faildCountOps.set(key, String.valueOf(++faild), 30, TimeUnit.MINUTES);
|
||||
return userRes.setResult(LoginCmdResult.LOGIN_NOUSER);
|
||||
}
|
||||
return userRes;
|
||||
|
||||
+2
-1
@@ -561,7 +561,8 @@ public class MessageServiceController implements MessageService {
|
||||
if (groupCount == null) {
|
||||
continue;
|
||||
}
|
||||
String userCount = hashOptions.get(userKey, RedisKeys.concat(RedisKeys.GROUP_UNREAD, group));
|
||||
String userCount =
|
||||
hashOptions.get(userKey, RedisKeys.concat(RedisKeys.GROUP_UNREAD, group.getGroupId()));
|
||||
|
||||
Integer unreadCount = userCount != null ? Integer.valueOf(groupCount) - Integer.valueOf(userCount)
|
||||
: Integer.valueOf(groupCount);
|
||||
|
||||
Reference in New Issue
Block a user