/**
* 错误登录记录,返回是否允许登录true/false和登录错误次数
*/
public HashMap<String, Integer> getLoginConfine(String condition) {
HashMap<String, Integer> flag = new HashMap<String, Integer>();
try {
//查询错误登录记录表中有无此用户登录错误信息
LoginConfine confine = service.loginError(condition);
if (confine != null) {
/*
* 计算时间差
*/
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date d1 = df.parse(SystemUtils.dateFormatString(new Date()));
Date d2 = df.parse(SystemUtils.dateFormatString(confine
.getLoginTime()));
long diff = d1.getTime() - d2.getTime();
long days = diff / (1000 * 60 * 60 * 24);
if (confine.getErrorNum() < 5) {
if (days >= 1) {
service.deleteErrorNum(condition);
flag.put("true", 0);
} else if (days < 1) {
flag.put("true", confine.getErrorNum());
}
} else if (confine.getErrorNum() >= 5) {
if (days >= 1) {
service.deleteErrorNum(condition);
flag.put("true", 0);
} else if (days < 1) {
flag.put("false", confine.getErrorNum());
}
}
} else {
flag.put("true", 0);
}
} catch (Exception e) {
e.printStackTrace();
}
return flag;
}
/------------------------------------------table sql-------------------------/
delimiter $$
CREATE TABLE `login_confine` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` varchar(32) NOT NULL,
`user_name` varchar(45) NOT NULL,
`error_num` int(11) NOT NULL,
`login_time` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='商户登录错误记录表'$$