Tôi hiện đang sử dụng django.contrib.auth.views.password_password_reset_confirm
để thay đổi mật khẩu của người dùng. Đây là cách các url của tôi trông:Thực hiện một độ dài tối thiểu trong mật khẩu Django
from django.contrib.auth import views as auth_views
url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
redirect_if_loggedin(auth_views.password_reset_confirm),
name='auth_password_reset_confirm'),
Hiện nay, tôi đang làm nó trực tiếp vào thân cây django -
# django.contrib.auth.views
def clean_new_password2(self):
password1 = self.cleaned_data.get('new_password1')
password2 = self.cleaned_data.get('new_password2')
if password1 and password2:
if len(password1) < 8:
raise forms.ValidationError(_("Password must be at least 8 chars."))
if password1 != password2:
raise forms.ValidationError(_("The two password fields didn't match."))
return password2
Chắc chắn phải có một cách tốt hơn.
Sẽ không 'nếu len (password1) <7' chấp nhận một pa ssword của chiều dài 7 (mà không phải là ít nhất 8)? – Dirk