1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-02 15:38:15 +00:00

[auth] Enlarge login attempt limit, and fix login attempts bug

This commit is contained in:
zhengxie
2014-07-07 14:14:18 +08:00
parent 94268403e8
commit 61f4d8bb38
2 changed files with 4 additions and 3 deletions

View File

@@ -84,18 +84,19 @@ def _incr_login_faied_attempts(username=None, ip=None):
Returns new value of failed attempts. Returns new value of failed attempts.
""" """
timeout = settings.LOGIN_ATTEMPT_TIMEOUT timeout = settings.LOGIN_ATTEMPT_TIMEOUT
username_attempts = 0
ip_attempts = 0
if username: if username:
try: try:
username_attempts = cache.incr(LOGIN_ATTEMPT_PREFIX + username) username_attempts = cache.incr(LOGIN_ATTEMPT_PREFIX + username)
except ValueError: except ValueError:
username_attempts = 0
cache.set(LOGIN_ATTEMPT_PREFIX + username, 0, timeout) cache.set(LOGIN_ATTEMPT_PREFIX + username, 0, timeout)
if ip: if ip:
try: try:
ip_attempts = cache.incr(LOGIN_ATTEMPT_PREFIX + ip) ip_attempts = cache.incr(LOGIN_ATTEMPT_PREFIX + ip)
except ValueError: except ValueError:
ip_attempts = 0
cache.set(LOGIN_ATTEMPT_PREFIX + ip, 0, timeout) cache.set(LOGIN_ATTEMPT_PREFIX + ip, 0, timeout)
return max(username_attempts, ip_attempts) return max(username_attempts, ip_attempts)

View File

@@ -375,7 +375,7 @@ LOGGING = {
} }
#Login Attempt #Login Attempt
LOGIN_ATTEMPT_LIMIT = 3 LOGIN_ATTEMPT_LIMIT = 10
LOGIN_ATTEMPT_TIMEOUT = 15 * 60 # in seconds (default: 15 minutes) LOGIN_ATTEMPT_TIMEOUT = 15 * 60 # in seconds (default: 15 minutes)
# Age of cookie, in seconds (default: 1 day). # Age of cookie, in seconds (default: 1 day).