From b2670bbcc0d8089bec083527831516314031efb0 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Fri, 12 Dec 2014 23:23:08 -0800 Subject: [PATCH] log failed login attempts I mean like "[2014-12-13 07:22:09,573] INFO [core.signals:11] login attempt for username 'Jennifer_Userton' failed" --- core/__init__.py | 12 ++++++++++++ core/signals.py | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 core/signals.py diff --git a/core/__init__.py b/core/__init__.py index e69de29..7add051 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -0,0 +1,12 @@ +from django.apps import AppConfig + +from core.signals import log_failed_login + +class FinetoothConfig(AppConfig): + name = "core" + verbose_name = "Finetooth Core" + + def ready(self): + import core.signals + +default_app_config = "core.FinetoothConfig" diff --git a/core/signals.py b/core/signals.py new file mode 100644 index 0000000..67c9cec --- /dev/null +++ b/core/signals.py @@ -0,0 +1,12 @@ +import logging + +from django.contrib.auth.signals import user_login_failed +from django.dispatch import receiver + +logger = logging.getLogger(__name__) + +@receiver(user_login_failed) +def log_failed_login(sender, **kwargs): + logger.info("login attempt for username '{}' failed".format( + kwargs['credentials']['username']) + )