Fixed #7833 -- Improved UserCreationForm password validation
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.
This commit is contained in:
parent
121fd109de
commit
09a719a4e6
|
@ -89,9 +89,9 @@ class UserCreationForm(forms.ModelForm):
|
||||||
raise forms.ValidationError(self.error_messages['duplicate_username'])
|
raise forms.ValidationError(self.error_messages['duplicate_username'])
|
||||||
|
|
||||||
def clean_password2(self):
|
def clean_password2(self):
|
||||||
password1 = self.cleaned_data.get("password1", "")
|
password1 = self.cleaned_data.get("password1")
|
||||||
password2 = self.cleaned_data["password2"]
|
password2 = self.cleaned_data.get("password2")
|
||||||
if password1 != password2:
|
if password1 and password2 and password1 != password2:
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(
|
||||||
self.error_messages['password_mismatch'])
|
self.error_messages['password_mismatch'])
|
||||||
return password2
|
return password2
|
||||||
|
|
|
@ -65,6 +65,7 @@ class UserCreationFormTest(TestCase):
|
||||||
form = UserCreationForm(data)
|
form = UserCreationForm(data)
|
||||||
self.assertFalse(form.is_valid())
|
self.assertFalse(form.is_valid())
|
||||||
self.assertEqual(form['password1'].errors, required_error)
|
self.assertEqual(form['password1'].errors, required_error)
|
||||||
|
self.assertEqual(form['password2'].errors, [])
|
||||||
|
|
||||||
def test_success(self):
|
def test_success(self):
|
||||||
# The success case.
|
# The success case.
|
||||||
|
|
Loading…
Reference in New Issue