当前位置:网站首页>User password verification
User password verification
2022-08-03 04:43:00 【Dzooooone_】
Password verification-lock
import java.util.Map;import javax.annotation.Resource;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Component;import com.google.common.collect.Maps;import com.inesa.basic.business.server.service.BasicUserInfoService;import com.inesa.business.model.AuthorityResponse;import com.inesa.business.model.BasicUserInfoVo;@Componentpublic class AuthorityTools {@Resourceprivate BasicUserInfoService userService;/*** The maximum number of logins allowed*/@Value("${authority.retry.limit:3}")private int retryLimit;/*** User lockout time*/@Value("#{${authority.retry.lock:5} * 60 * 1000L}")private long lockTime;/*** User login lockout time*/private Map userLockTime = Maps.newConcurrentMap();/*** The number of user login failures*/private Map userLongTime = Maps.newConcurrentMap();/*** Encrypt information** @param* @return*/public String encoder(String password) {return CryptoUtil.encrypt(password);}/*** Verify that it is correct** @param username* @param password Number of times to log in* @return*/public AuthorityResponse authority(String username, String password) {BasicUserInfoVo user = userService.findByUserName(username);// Verify user existsif (user == null) {return AuthorityResponse.builder().check(false).error("User does not exist").build();}// Determine if the user is lockedif (userLockTime.containsKey(user.getId())) {if (System.currentTimeMillis() - userLockTime.get(user.getId()) < lockTime) {if (userLongTime.getOrDefault(user.getId(), 0) > retryLimit) {int minutes = (int) ((System.currentTimeMillis() - userLockTime.get(user.getId())) / 60000L);return AuthorityResponse.builder().check(false).error(String.format("User is locked, please try again in %s minutes", lockTime / 60000L - minutes)).build();}} else {// If the time of the last login failure has exceeded the time limit, reset the number of failed loginsuserLockTime.remove(user.getId());userLongTime.remove(user.getId());}}if (user.getState() == BasicUserInfoVo.DISABLE) {return AuthorityResponse.builder().check(false).error("User has been disabled").build();}if (user.getState() == BasicUserInfoVo.LOCKED) {return AuthorityResponse.builder().check(false).error("User has been locked out").build();}// Verify that the password is incorrectif (!password.equals(user.getPassword())) {// Update the number of failed logins after login failures, and update the time of failed loginsint retriedTimes = userLongTime.getOrDefault(user.getId(), 0);retrieveTimes++;userLongTime.put(user.getId(), retriedTimes);userLockTime.put(user.getId(), System.currentTimeMillis());return AuthorityResponse.builder().check(false).error("Password error").build();}return AuthorityResponse.builder().userId(user.getId()).check(true).build();}} 边栏推荐
- typescript45-接口之间的兼容性
- 常见荧光染料修饰多种基团及其激发和发射波长数据一览数据
- Two ways to simulate multi-user login in Jmeter
- 4.深度学习的几何解释与梯度的优化
- 私域流量时代来临,电商企业如何布局?
- 2022/08/02 Study Notes (day22) Multithreading
- GIS数据漫谈(五)— 地理坐标系统
- typescript49-交叉类型
- Test drive: project management module - curd development project
- 刚上线就狂吸70W粉,新型商业模式“分享购”来了,你知道吗?
猜你喜欢
随机推荐
BIOTIN ALKYNE CAS:773888-45-2价格,供应商
刚上线就狂吸70W粉,新型商业模式“分享购”来了,你知道吗?
Technology Sharing | How to do assertion verification for xml format in interface automation testing?
t条件判断语句与if循环
Harmony OS Date ano UI 】 【 】 the basic operation
2022/08/02 Study Notes (day22) Multithreading
刚上线就狂吸70W粉,新型商业模式“分享购”来了,你知道吗?
获取Ip工具类
2022河南萌新联赛第(四)场:郑州轻工业大学 E - 睡大觉
传统企业如何转型社交电商,泰山众筹的玩法有哪些?
How to prepare for the test interface test data
私域流量引流方法?分享购火爆的商业模式,你值得拥有
Shell之条件语句
WinForm的控件二次开发
多肽介导PEG磷脂——靶向功能材料之DSPE-PEG-RGD/TAT/NGR/APRPG
8.电影评论分类:二分类问题
数字孪生园区场景中的坐标知识
[Harmony OS] [ARK UI] ETS context basic operations
【软件工程之美 - 专栏笔记】35 | 版本发布:软件上线只是新的开始
[Harmony OS] [ArkUI] ets development graphics and animation drawing









