Skip to content

Fixed #28127 -- Allowed UserCreationForm's password validation to check all user fields. #8408

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

Merged
merged 1 commit into from
Jun 21, 2017

Conversation

jambonrose
Copy link
Contributor

  • UserCreationForm runs password validation against full user instance,
    checking all fields in the form, not just the username

try:
password_validation.validate_password(password, self.instance)
except forms.ValidationError as error:
self.add_error("password2", error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use single quotes.

return password2

def _post_clean(self):
super()._post_clean() # creates self.instance
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the comment, I'd say # updates self.instance with form data (since self.instance is first assigned in ModelForm.init()` "creates" might be confusing)

return password2

def _post_clean(self):
super()._post_clean() # creates self.instance
password = self.cleaned_data.get("password2")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use single quotes.

@@ -54,6 +54,10 @@ Minor features
* The default iteration count for the PBKDF2 password hasher is increased from
36,000 to 100,000.

* The :class:`~django.contrib.auth.forms.UserCreationForm` and subclasses will
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider this a bug fix rather than a minor feature so no release note is needed.

@@ -872,3 +872,118 @@ def test_password_whitespace_not_stripped(self):
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data['password1'], data['password1'])
self.assertEqual(form.cleaned_data['password2'], data['password2'])


@override_settings(AUTH_PASSWORD_VALIDATORS=[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's enough to include a single test in UserCreationFormTest. Testing for both first_name and last_name seem unnecessary.

Adding tests for PasswordChangeForm that aren't affected by this change shouldn't be done in this commit.

@timgraham timgraham changed the title Fixed #28127 - New user pw validated on all fields Fixed #28127 -- Allowed UserCreationForm's password validation to check all user fields. Jun 14, 2017
@jambonrose
Copy link
Contributor Author

Hi Tim,
Thanks for looking over the PR!

Changes made! I think this is good to go. Please let me know if I misunderstood any of your instructions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants