Skip to content

Commit 536db42

Browse files
Alexander Gaevskytimgraham
Alexander Gaevsky
authored andcommitted
Fixed #26097 -- Added password_validators_help_text_html to UserCreationForm.
1 parent 2d26b46 commit 536db42

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

django/contrib/admin/static/admin/css/base.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,15 @@ p.mini {
187187
margin-top: -3px;
188188
}
189189

190-
.help, p.help, form p.help, div.help, form div.help {
190+
.help, p.help, form p.help, div.help, form div.help, div.help li {
191191
font-size: 11px;
192192
color: #999;
193193
}
194194

195+
div.help ul {
196+
margin-bottom: 0;
197+
}
198+
195199
.help-tooltip {
196200
cursor: help;
197201
}

django/contrib/auth/forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class UserCreationForm(forms.ModelForm):
7979
label=_("Password"),
8080
strip=False,
8181
widget=forms.PasswordInput,
82+
help_text=password_validation.password_validators_help_text_html(),
8283
)
8384
password2 = forms.CharField(
8485
label=_("Password confirmation"),

docs/releases/1.11.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ Minor features
106106
:class:`~django.contrib.auth.views.LogoutView` allows specifying a set of
107107
hosts that are safe for redirecting after login and logout.
108108

109+
* Added password validators ``help_text`` to
110+
:class:`~django.contrib.auth.forms.UserCreationForm`.
111+
109112
:mod:`django.contrib.contenttypes`
110113
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
111114

tests/auth_tests/test_forms.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ def test_password_whitespace_not_stripped(self):
236236
self.assertEqual(form.cleaned_data['password1'], data['password1'])
237237
self.assertEqual(form.cleaned_data['password2'], data['password2'])
238238

239+
@override_settings(AUTH_PASSWORD_VALIDATORS=[
240+
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
241+
])
242+
def test_password_help_text(self):
243+
form = UserCreationForm()
244+
self.assertEqual(
245+
form.fields['password1'].help_text,
246+
'<ul><li>Your password can&#39;t be too similar to your other personal information.</li></ul>'
247+
)
248+
239249

240250
# To verify that the login form rejects inactive users, use an authentication
241251
# backend that allows them.

0 commit comments

Comments
 (0)