对于连续失败登录应用系统5次的帐号,需锁定该帐号至少30分钟不允许登录。
这里也用简单的map集合进行判定,功能能实现,但并不是很完美,不用更改数据库的表字段
1、首先建立一个用户登陆失败的实体类
public class UserErrorLoginRecord {
//登录时间
private Date longinTime;
//错误次数
private Integer errorNum;
}
2、再登陆的contorller里
private static Map LOG_MAP = new HashMap();
3、再判断用户登陆系统的具体方法里
UserErrorLoginRecord userError = null;
boolean flag = true; //默认每次进入都是true,当输入失败5次后,设置为false,直接锁定当前账户30分钟。
用户每次登陆失败就进行存储一次,如下
userError = LOG_MAP.get(username);
if (userError == null) {
userError = new UserErrorLoginRecord();
userError.setErrorNum(1);
userError.setLonginTime(new Date());
LOG_MAP.put(username, userError);
}else{
int loginNumber = userError.getErrorNum();