Skip to content

Commit

Permalink
🦄 fix login error count
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Mar 4, 2017
1 parent 359593d commit 745ec04
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/main/java/com/tale/controller/admin/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public RestResponse doLogin(@QueryParam String username,

Integer error_count = cache.get("login_error_count");
try {
error_count = null == error_count ? 0 : error_count;

if(null != error_count && error_count > 3){
return RestResponse.fail("您输入密码已经错误超过3次,请10分钟后尝试");
}

Users user = usersService.login(username, password);
session.attribute(TaleConst.LOGIN_SESSION_KEY, user);
if (StringKit.isNotBlank(remeber_me)) {
Expand All @@ -68,12 +74,10 @@ public RestResponse doLogin(@QueryParam String username,
temp.setLogged(DateKit.getCurrentUnixTime());
usersService.update(temp);
LOGGER.info("登录成功:{}", JSONKit.toJSONString(request.querys()));
cache.set("login_error_count", 0);
logService.save(LogActions.LOGIN, JSONKit.toJSONString(request.querys()), request.address(), user.getUid());
} catch (Exception e) {
error_count = null == error_count ? 1 : error_count + 1;
if(null != error_count && error_count > 3){
return RestResponse.fail("您输入密码已经错误超过3次,请10分钟后尝试");
}
error_count+=1;
cache.set("login_error_count", error_count, 10 * 60);
String msg = "登录失败";
if (e instanceof TipException) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tale/init/WebContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void init(BConfig bConfig, ServletContext sec) {

TaleConst.MAX_FILE_SIZE = bConfig.config().getInt("app.max-file-size", 20480);

TaleConst.AES_SALT = bConfig.config().get("app.salt", StringKit.getRandomChar(16));
TaleConst.AES_SALT = bConfig.config().get("app.salt", "012c456789abcdef");
TaleConst.OPTIONS.addAll(optionsService.getOptions());
String ips = TaleConst.OPTIONS.get(Types.BLOCK_IPS, "");
if (StringKit.isNotBlank(ips)) {
Expand Down

0 comments on commit 745ec04

Please sign in to comment.