diff options
| author | Bobby <[email protected]> | 2023-01-08 13:01:35 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2023-01-08 13:01:35 -0500 |
| commit | 1a45d7ccb31d641c3d175aab862866f8b9a2f8cd (patch) | |
| tree | d6749b028f7d04e51b9dab54811c7898e34e0e91 /users | |
| parent | 8d270d0da154d8a863401581e742de7a0eb191ed (diff) | |
| download | thatcomputerscientist-1a45d7ccb31d641c3d175aab862866f8b9a2f8cd.tar.xz thatcomputerscientist-1a45d7ccb31d641c3d175aab862866f8b9a2f8cd.zip | |
Password length validation
Diffstat (limited to 'users')
| -rw-r--r-- | users/forms.py | 6 | ||||
| -rw-r--r-- | users/views.py | 3 |
2 files changed, 7 insertions, 2 deletions
diff --git a/users/forms.py b/users/forms.py index 8b02fef5..43b9230a 100644 --- a/users/forms.py +++ b/users/forms.py @@ -14,8 +14,8 @@ from .tokens import account_activation_token class RegisterForm(forms.Form): username = forms.CharField(label='Username', max_length=30, min_length=4) email = forms.EmailField(label='Email') - password1 = forms.CharField(label='Password', widget=forms.PasswordInput) - password2 = forms.CharField(label='Password (again)', widget=forms.PasswordInput) + password1 = forms.CharField(label='Password', widget=forms.PasswordInput, min_length=8) + password2 = forms.CharField(label='Password (again)', widget=forms.PasswordInput, min_length=8) captcha = forms.CharField(label='Captcha', max_length=6) expected_captcha = None @@ -32,6 +32,8 @@ class RegisterForm(forms.Form): if password1 and password2: if password1 != password2: raise forms.ValidationError('Passwords do not match.') + if len(password1) < 8: + raise forms.ValidationError('Password must be at least 8 characters long.') if str.lower(captcha) != str.lower(self.expected_captcha): raise forms.ValidationError('Captcha does not match.') if User.objects.filter(username=cleaned_data.get('username')).exists(): diff --git a/users/views.py b/users/views.py index 02f82902..61724bab 100644 --- a/users/views.py +++ b/users/views.py @@ -111,6 +111,9 @@ def change_password(request): user = User.objects.get(username=username) if user.check_password(old_password): if new_password == confirm_password: + if len(new_password) < 8: + messages.error(request, 'The new password must be at least 8 characters long!') + return HttpResponseRedirect(request.META.get('HTTP_REFERER')) user.set_password(new_password) user.save() update_session_auth_hash(request, user) |
