27 lines
889 B
Python
27 lines
889 B
Python
from fastapi import HTTPException, status
|
|
|
|
|
|
def check_password_reqs(password: str):
|
|
"""
|
|
Make sure the entered password meets the security requirements:
|
|
1. At least 8 characters
|
|
2. At least one digit
|
|
3. At least one uppercase letter
|
|
"""
|
|
if len(password) < 8:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_400_BAD_REQUEST,
|
|
detail="Password must be at least 8 characters",
|
|
)
|
|
if not any(char.isdigit() for char in password):
|
|
raise HTTPException(
|
|
status_code=status.HTTP_400_BAD_REQUEST,
|
|
detail="Password must contain at least one digit",
|
|
)
|
|
if not any(char.isupper() for char in password):
|
|
raise HTTPException(
|
|
status_code=status.HTTP_400_BAD_REQUEST,
|
|
detail="Password must contain at least one uppercase letter",
|
|
)
|
|
return
|