Exemplo n.º 1
0
 def is_user_blocked(cls, username):
     user = {}
     with cls._lock:
         now = datetime.now()
         user = cls._failed_logins.get(username)
         #Block username for 'login_block_timeout' seconds if failed consecutively for 'login_retry_times' times
         if user and len(user['time']
                         ) >= SystemSettingsManage.get_login_retry_times():
             dt = abs((now - user['time'][-1]).total_seconds())
             if dt < SystemSettingsManage.get_tamper_protection_timeout():
                 return True
             cls._failed_logins.pop(username, None)
     return False
Exemplo n.º 2
0
    def login_failed(cls, username):
        with cls._lock:
            now = datetime.now()
            user = cls._failed_logins.get(username, {})
            if user:
                user['time'] = [
                    dt for dt in user['time']
                    if abs((now - dt).total_seconds()) <
                    SystemSettingsManage.get_login_retry_window()
                ]
                if len(user['time']
                       ) >= SystemSettingsManage.get_login_retry_times():
                    user['time'].pop(0, None)
            else:
                user['time'] = []

            user['time'].append(now)
            cls._failed_logins[username] = user