summaryrefslogtreecommitdiffstats
path: root/api/user.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2015-08-02 09:17:37 -0800
committerCorey Hulen <corey@hulen.com>2015-08-02 09:17:37 -0800
commit4d1562c5de377741734a0ad4e8eb30a83d301262 (patch)
tree74d1d7821b3863231c2d9429b6ccb48728661b30 /api/user.go
parentadc8def9e06a7908d5f092088922dc26cbb277df (diff)
parentd93bf60248f066542d0851a7b6847f925975d77f (diff)
downloadchat-4d1562c5de377741734a0ad4e8eb30a83d301262.tar.gz
chat-4d1562c5de377741734a0ad4e8eb30a83d301262.tar.bz2
chat-4d1562c5de377741734a0ad4e8eb30a83d301262.zip
Merge pull request #273 from mattermost/mm-1355
Fixes mm-1355 adds rate limiting apis
Diffstat (limited to 'api/user.go')
-rw-r--r--api/user.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/api/user.go b/api/user.go
index 54337e207..a42f81cf1 100644
--- a/api/user.go
+++ b/api/user.go
@@ -284,13 +284,32 @@ func LoginByEmail(c *Context, w http.ResponseWriter, r *http.Request, email, nam
}
func checkUserPassword(c *Context, user *model.User, password string) bool {
+
+ if user.FailedAttempts >= utils.Cfg.ServiceSettings.AllowedLoginAttempts {
+ c.LogAuditWithUserId(user.Id, "fail")
+ c.Err = model.NewAppError("checkUserPassword", "Your account is locked because of too many failed password attempts. Please reset your password.", "user_id="+user.Id)
+ c.Err.StatusCode = http.StatusForbidden
+ return false
+ }
+
if !model.ComparePassword(user.Password, password) {
c.LogAuditWithUserId(user.Id, "fail")
c.Err = model.NewAppError("checkUserPassword", "Login failed because of invalid password", "user_id="+user.Id)
c.Err.StatusCode = http.StatusForbidden
+
+ if result := <-Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, user.FailedAttempts+1); result.Err != nil {
+ c.LogError(result.Err)
+ }
+
return false
+ } else {
+ if result := <-Srv.Store.User().UpdateFailedPasswordAttempts(user.Id, 0); result.Err != nil {
+ c.LogError(result.Err)
+ }
+
+ return true
}
- return true
+
}
// User MUST be validated before calling Login