Merge pull request #1318 from leonelcamara/admin_lockout

Check if host is denied before verifying password
This commit is contained in:
mdipierro
2016-05-04 13:30:14 -05:00
2 changed files with 9 additions and 2 deletions
@@ -121,6 +121,9 @@ def index():
send = URL('site') send = URL('site')
if session.authorized: if session.authorized:
redirect(send) redirect(send)
elif failed_login_count() >= allowed_number_of_attempts:
time.sleep(2 ** allowed_number_of_attempts)
raise HTTP(403)
elif request.vars.password: elif request.vars.password:
if verify_password(request.vars.password[:1024]): if verify_password(request.vars.password[:1024]):
session.authorized = True session.authorized = True
+6 -2
View File
@@ -104,13 +104,12 @@ def write_hosts_deny(denied_hosts):
portalocker.unlock(f) portalocker.unlock(f)
f.close() f.close()
def login_record(success=True): def login_record(success=True):
denied_hosts = read_hosts_deny() denied_hosts = read_hosts_deny()
val = (0, 0) val = (0, 0)
if success and request.client in denied_hosts: if success and request.client in denied_hosts:
del denied_hosts[request.client] del denied_hosts[request.client]
elif not success and not request.is_local: elif not success:
val = denied_hosts.get(request.client, (0, 0)) val = denied_hosts.get(request.client, (0, 0))
if time.time() - val[1] < expiration_failed_logins \ if time.time() - val[1] < expiration_failed_logins \
and val[0] >= allowed_number_of_attempts: and val[0] >= allowed_number_of_attempts:
@@ -121,6 +120,11 @@ def login_record(success=True):
write_hosts_deny(denied_hosts) write_hosts_deny(denied_hosts)
return val[0] return val[0]
def failed_login_count():
denied_hosts = read_hosts_deny()
val = denied_hosts.get(request.client, (0, 0))
return val[0]
# ########################################################### # ###########################################################
# ## session expiration # ## session expiration