Skip to content

Commit

Permalink
Fixed django#7833 -- Improved UserCreationForm password validation
Browse files Browse the repository at this point in the history
Make UserCreationForm password validation similar to
SetPasswordForm and AdminPasswordChangeForm, so as the match
check is only done when both passwords are supplied.
Thanks Mitar for the suggestion.
  • Loading branch information
claudep committed Aug 4, 2012
1 parent 121fd10 commit 09a719a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions django/contrib/auth/forms.py
Expand Up @@ -89,9 +89,9 @@ def clean_username(self):
raise forms.ValidationError(self.error_messages['duplicate_username'])

def clean_password2(self):
password1 = self.cleaned_data.get("password1", "")
password2 = self.cleaned_data["password2"]
if password1 != password2:
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
raise forms.ValidationError(
self.error_messages['password_mismatch'])
return password2
Expand Down
1 change: 1 addition & 0 deletions django/contrib/auth/tests/forms.py
Expand Up @@ -65,6 +65,7 @@ def test_both_passwords(self):
form = UserCreationForm(data)
self.assertFalse(form.is_valid())
self.assertEqual(form['password1'].errors, required_error)
self.assertEqual(form['password2'].errors, [])

def test_success(self):
# The success case.
Expand Down

0 comments on commit 09a719a

Please sign in to comment.