Spaces:
Sleeping
Sleeping
suhail
commited on
Commit
·
9ff393a
1
Parent(s):
8423e92
changes
Browse files- src/core/security.py +7 -5
- src/schemas/auth.py +8 -4
src/core/security.py
CHANGED
|
@@ -13,12 +13,14 @@ def hash_password(password: str) -> str:
|
|
| 13 |
"""
|
| 14 |
Hash a password using bcrypt.
|
| 15 |
|
| 16 |
-
|
| 17 |
-
password: Plain text password
|
| 18 |
-
|
| 19 |
-
Returns:
|
| 20 |
-
Hashed password string
|
| 21 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
return pwd_context.hash(password)
|
| 23 |
|
| 24 |
|
|
|
|
| 13 |
"""
|
| 14 |
Hash a password using bcrypt.
|
| 15 |
|
| 16 |
+
bcrypt has a hard limit of 72 bytes.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
"""
|
| 18 |
+
if len(password.encode("utf-8")) > 72:
|
| 19 |
+
raise HTTPException(
|
| 20 |
+
status_code=status.HTTP_400_BAD_REQUEST,
|
| 21 |
+
detail="Password must be at most 72 characters"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
return pwd_context.hash(password)
|
| 25 |
|
| 26 |
|
src/schemas/auth.py
CHANGED
|
@@ -4,11 +4,15 @@ from datetime import datetime
|
|
| 4 |
from typing import Optional
|
| 5 |
|
| 6 |
|
|
|
|
| 7 |
class SignupRequest(BaseModel):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
password: str = Field(
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
class SigninRequest(BaseModel):
|
|
|
|
| 4 |
from typing import Optional
|
| 5 |
|
| 6 |
|
| 7 |
+
|
| 8 |
class SignupRequest(BaseModel):
|
| 9 |
+
email: EmailStr
|
| 10 |
+
name: str
|
| 11 |
+
password: str = Field(
|
| 12 |
+
min_length=8,
|
| 13 |
+
max_length=72,
|
| 14 |
+
description="Password must be between 8 and 72 characters"
|
| 15 |
+
)
|
| 16 |
|
| 17 |
|
| 18 |
class SigninRequest(BaseModel):
|