feat(users): apply django password validators in auth flows
This commit is contained in:
29
core/validators/password.py
Normal file
29
core/validators/password.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import re
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
|
||||
class PasswordComplexityValidator:
|
||||
lower_pattern = re.compile(r"[a-z]")
|
||||
upper_pattern = re.compile(r"[A-Z]")
|
||||
digit_pattern = re.compile(r"\d")
|
||||
symbol_pattern = re.compile(r"[^A-Za-z0-9]")
|
||||
|
||||
message = (
|
||||
"Password must be at least 8 characters and include at least one lowercase "
|
||||
"letter, one uppercase letter, one digit, and one symbol."
|
||||
)
|
||||
code = "password_no_complexity"
|
||||
|
||||
def validate(self, password, user=None):
|
||||
if (
|
||||
len(password) < 8
|
||||
or not self.lower_pattern.search(password)
|
||||
or not self.upper_pattern.search(password)
|
||||
or not self.digit_pattern.search(password)
|
||||
or not self.symbol_pattern.search(password)
|
||||
):
|
||||
raise ValidationError(self.message, code=self.code)
|
||||
|
||||
def get_help_text(self):
|
||||
return self.message
|
||||
Reference in New Issue
Block a user