Reset attempt counters if they get memory hungry

This commit is contained in:
0livd 2017-07-12 18:23:04 +02:00
parent d8307f4672
commit b8685c0af2

View file

@ -149,6 +149,9 @@ class LoginThrottler():
return self._max_attempts - self._attempts.get(ip, [datetime.now(), 0])[1] return self._max_attempts - self._attempts.get(ip, [datetime.now(), 0])[1]
def increment_attempts_counter(self, ip): def increment_attempts_counter(self, ip):
# Reset all attempt counters when they get hungry for memory
if len(self._attempts) > 10000:
self.__init__()
if self._attempts.get(ip) is None: if self._attempts.get(ip) is None:
# Store first attempt date and number of attempts since # Store first attempt date and number of attempts since
self._attempts[ip] = [datetime.now(), 0] self._attempts[ip] = [datetime.now(), 0]