Skip to content

Commit

Permalink
Fixed #21291 -- Ensured inactive users cannot reset their passwords
Browse files Browse the repository at this point in the history
Thanks kz26 for the report and the suggested fix. Refs #19758.
  • Loading branch information
claudep committed Oct 19, 2013
1 parent 59a8808 commit 5f52590
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions django/contrib/auth/forms.py
Expand Up @@ -238,8 +238,9 @@ def save(self, domain_override=None,
from django.core.mail import send_mail
UserModel = get_user_model()
email = self.cleaned_data["email"]
users = UserModel._default_manager.filter(email__iexact=email)
for user in users:
active_users = UserModel._default_manager.filter(
email__iexact=email, is_active=True)
for user in active_users:
# Make sure that no email is sent to a user that actually has
# a password marked as unusable
if not user.has_usable_password():
Expand Down
1 change: 1 addition & 0 deletions django/contrib/auth/tests/test_forms.py
Expand Up @@ -436,6 +436,7 @@ def test_inactive_user(self):
user.save()
form = PasswordResetForm({'email': email})
self.assertTrue(form.is_valid())
form.save()
self.assertEqual(len(mail.outbox), 0)

def test_unusable_password(self):
Expand Down

0 comments on commit 5f52590

Please sign in to comment.