24 lines
691 B
Python
24 lines
691 B
Python
|
import re
|
||
|
from passlib.context import CryptContext
|
||
|
|
||
|
|
||
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||
|
|
||
|
|
||
|
def verify_password(plain_password, hashed_password):
|
||
|
return pwd_context.verify(plain_password, hashed_password)
|
||
|
|
||
|
|
||
|
def get_password_hash(password):
|
||
|
return pwd_context.hash(password)
|
||
|
|
||
|
|
||
|
def validate_password(password):
|
||
|
if len(password) < 8:
|
||
|
return "Le mot de passe est trop court (8 caractères minimum)"
|
||
|
elif re.search('[0-9]', password) is None:
|
||
|
return 'Le mot de passe doit contenir au moins un chiffre'
|
||
|
elif re.search('[A-Z]', password) is None:
|
||
|
return "Le mot de passe doit contenir au moins une majuscule"
|
||
|
return True
|