Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send email to user when a checker fails, eg: with weak password login at... #7

Merged
merged 2 commits into from
Dec 9, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion secure_login/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ def authenticate(self, username=None, password=None, **kwargs):
"SECURE_LOGIN_ON_FAIL",
DEFAULT_ON_FAIL)

checker_failed = False
for checker in checkers:
if not get_callable(checker)(username, password, **kwargs):
return None
checker_failed = True
break
if checker_failed:
for callable_ in on_fail_callables:
get_callable(callable_)(username, password, **kwargs)
return None

user = super(SecureLoginBackendMixin, self).authenticate(username,
password,
**kwargs)
Expand Down
17 changes: 17 additions & 0 deletions secure_login/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,20 @@ def test_email_sent_on_wrong_password(self):
self.assertFalse(authenticate(username=username,
password=password + "1"))
self.assertEqual(len(mail.outbox), 1)

@override_settings(
SECURE_LOGIN_CHECKERS=[
"secure_login.checkers.no_weak_passwords",
]
)
def test_email_sent_on_weak_password(self):
username = "hello"
password = "hello"
good_password = "a-l0ng-pa55w0rd-@^&"
user = User.objects.create(username=username)
user.set_password(good_password)
user.save()

self.assertFalse(authenticate(username=username,
password=password))
self.assertEqual(len(mail.outbox), 1)