1
0
Fork 0

Use password validation in register view

This commit is contained in:
Mouse Reeve 2022-07-15 09:59:57 -07:00
parent a2540e8361
commit 4a65ee326a
2 changed files with 17 additions and 0 deletions

View file

@ -1,4 +1,6 @@
""" Forms for the landing pages """
from django.contrib.auth.password_validation import validate_password
from django.core.exceptions import ValidationError
from django.forms import PasswordInput
from django.utils.translation import gettext_lazy as _
@ -28,6 +30,10 @@ class RegisterForm(CustomForm):
"""Check if the username is taken"""
cleaned_data = super().clean()
localname = cleaned_data.get("localname").strip()
try:
validate_password(cleaned_data.get("password"))
except ValidationError as err:
self.add_error("password", err)
if models.User.objects.filter(localname=localname).first():
self.add_error("localname", _("User with this username already exists"))