Skip to content

Commit

Permalink
feat : use regex verification
Browse files Browse the repository at this point in the history
  • Loading branch information
BLEMENT33 committed Jun 4, 2024
1 parent 0e2d28f commit ce73e26
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions app/utils/validators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

"""
A collection of Pydantic validators
See https://pydantic-docs.helpmanual.io/usage/validators/#reuse-validators
Expand All @@ -10,18 +12,11 @@ def password_validator(password: str) -> str:
This function is intended to be used as a Pydantic validator:
https://pydantic-docs.helpmanual.io/usage/validators/#reuse-validators
"""
nb_number, nb_special, nb_maj, nb_min = 0, 0, 0, 0
for i in password:
if i.isnumeric():
nb_number += 1
elif not i.isalpha():
nb_special += 1
elif i.isupper():
nb_maj += 1
elif i.islower():
nb_min += 1

if len(password) < 6 or nb_number < 1 or nb_special < 1 or nb_min < 1 or nb_maj < 1:
password = password.strip()
if not re.fullmatch(
r"""(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$€%^&*()_+\-.,.?":{}|<>'/;\[\]]){6,}""",
password,
):
raise ValueError(
"The password must be at least 6 characters long and contain at least one number, one special character, one majuscule and one minuscule.",
)
Expand Down

0 comments on commit ce73e26

Please sign in to comment.