Commit 392d800b authored by 廖旭伟's avatar 廖旭伟

登录错误5次账号锁定

parent 824c3d52
...@@ -32,6 +32,7 @@ import com.mortals.xhx.module.user.service.UserService; ...@@ -32,6 +32,7 @@ import com.mortals.xhx.module.user.service.UserService;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -61,6 +62,10 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -61,6 +62,10 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
@Autowired @Autowired
private UserPwdRecordDao userPwdRecordDao; private UserPwdRecordDao userPwdRecordDao;
// 当日密码错误次数(默认60分钟)
@Value("${login.errorCount:5}")
private int ErrorCount;
/** /**
* @param data * @param data
* @return * @return
...@@ -208,14 +213,16 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -208,14 +213,16 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
if (sysUser.getLoginLock() == null) { if (sysUser.getLoginLock() == null) {
sysUser.setLoginLock(0); sysUser.setLoginLock(0);
} }
//取消账户锁定功能 //账户锁定功能
/* if (sysUser.getLoginLock() == 1 && sysUser.getLockTime() != null) { if (sysUser.getLoginLock() == 1 && sysUser.getLockTime() != null) {
String nowStr = DateUtils.getCurrStrDate(); String nowStr = DateUtils.getCurrStrDate();
String loginDateStr = DateUtils.getDateTime(sysUser.getLockTime(), "yyyy-MM-dd"); String loginDateStr = DateUtils.getDateTime(sysUser.getLockTime(), "yyyy-MM-dd");
if (nowStr.equals(loginDateStr)) { if (nowStr.equals(loginDateStr)) {
throw new AppException("此账号当天密码错误次数已达上限,已被锁定"); throw new AppException("此账号当天密码错误次数已达上限"+ErrorCount+"次,已被锁定");
}else {
sysUser.setLoginLock(0);
}
} }
}*/
try { try {
if (StringUtils.isNotEmpty(sysUser.getSaltKey())) { if (StringUtils.isNotEmpty(sysUser.getSaltKey())) {
...@@ -225,7 +232,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE ...@@ -225,7 +232,7 @@ public class UserServiceImpl extends AbstractCRUDCacheServiceImpl<UserDao, UserE
UserEntity update = new UserEntity(); UserEntity update = new UserEntity();
update.setId(sysUser.getId()); update.setId(sysUser.getId());
update.setErrorCount(sysUser.getErrorCount() + 1); update.setErrorCount(sysUser.getErrorCount() + 1);
if (update.getErrorCount() == 5) { if (update.getErrorCount() == ErrorCount) {
update.setLoginLock(1); update.setLoginLock(1);
update.setLockTime(new Date()); update.setLockTime(new Date());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment