Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
a96b981d
Kaydet (Commit)
a96b981d
authored
Nis 25, 2017
tarafından
Andrew Pinkham
Kaydeden (comit)
Tim Graham
Haz 21, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28127 -- Allowed UserCreationForm's password validation to check all user fields.
üst
b1cbbe92
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
forms.py
django/contrib/auth/forms.py
+11
-2
test_forms.py
tests/auth_tests/test_forms.py
+22
-0
No files found.
django/contrib/auth/forms.py
Dosyayı görüntüle @
a96b981d
...
@@ -100,10 +100,19 @@ class UserCreationForm(forms.ModelForm):
...
@@ -100,10 +100,19 @@ class UserCreationForm(forms.ModelForm):
self
.
error_messages
[
'password_mismatch'
],
self
.
error_messages
[
'password_mismatch'
],
code
=
'password_mismatch'
,
code
=
'password_mismatch'
,
)
)
self
.
instance
.
username
=
self
.
cleaned_data
.
get
(
'username'
)
password_validation
.
validate_password
(
self
.
cleaned_data
.
get
(
'password2'
),
self
.
instance
)
return
password2
return
password2
def
_post_clean
(
self
):
super
()
.
_post_clean
()
# Validate the password after self.instance is updated with form data
# by super().
password
=
self
.
cleaned_data
.
get
(
'password2'
)
if
password
:
try
:
password_validation
.
validate_password
(
password
,
self
.
instance
)
except
forms
.
ValidationError
as
error
:
self
.
add_error
(
'password2'
,
error
)
def
save
(
self
,
commit
=
True
):
def
save
(
self
,
commit
=
True
):
user
=
super
()
.
save
(
commit
=
False
)
user
=
super
()
.
save
(
commit
=
False
)
user
.
set_password
(
self
.
cleaned_data
[
"password1"
])
user
.
set_password
(
self
.
cleaned_data
[
"password1"
])
...
...
tests/auth_tests/test_forms.py
Dosyayı görüntüle @
a96b981d
...
@@ -239,6 +239,28 @@ class UserCreationFormTest(TestDataMixin, TestCase):
...
@@ -239,6 +239,28 @@ class UserCreationFormTest(TestDataMixin, TestCase):
'<ul><li>Your password can't be too similar to your other personal information.</li></ul>'
'<ul><li>Your password can't be too similar to your other personal information.</li></ul>'
)
)
@override_settings
(
AUTH_PASSWORD_VALIDATORS
=
[
{
'NAME'
:
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'
},
])
def
test_user_create_form_validates_password_with_all_data
(
self
):
"""UserCreationForm password validation uses all of the form's data."""
class
CustomUserCreationForm
(
UserCreationForm
):
class
Meta
(
UserCreationForm
.
Meta
):
model
=
User
fields
=
(
'username'
,
'email'
,
'first_name'
,
'last_name'
)
form
=
CustomUserCreationForm
({
'username'
:
'testuser'
,
'password1'
:
'testpassword'
,
'password2'
:
'testpassword'
,
'first_name'
:
'testpassword'
,
'last_name'
:
'lastname'
,
})
self
.
assertFalse
(
form
.
is_valid
())
self
.
assertEqual
(
form
.
errors
[
'password2'
],
[
'The password is too similar to the first name.'
],
)
# To verify that the login form rejects inactive users, use an authentication
# To verify that the login form rejects inactive users, use an authentication
# backend that allows them.
# backend that allows them.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment