Spaces:
Running
Running
Update admin_routes.py
Browse files- admin_routes.py +9 -4
admin_routes.py
CHANGED
@@ -190,12 +190,17 @@ def verify_token(credentials: HTTPAuthorizationCredentials = Depends(security))
|
|
190 |
def hash_password(password: str, salt: str = None) -> tuple[str, str]:
|
191 |
"""Hash password with bcrypt. Returns (hash, salt)"""
|
192 |
if salt is None:
|
193 |
-
|
|
|
|
|
194 |
else:
|
195 |
-
salt
|
|
|
196 |
|
197 |
-
|
198 |
-
|
|
|
|
|
199 |
|
200 |
def verify_password(password: str, stored_hash: str, salt: str = None) -> bool:
|
201 |
"""Verify password against hash - supports both bcrypt and SHA256"""
|
|
|
190 |
def hash_password(password: str, salt: str = None) -> tuple[str, str]:
|
191 |
"""Hash password with bcrypt. Returns (hash, salt)"""
|
192 |
if salt is None:
|
193 |
+
# Generate new salt
|
194 |
+
salt_bytes = bcrypt.gensalt()
|
195 |
+
salt = salt_bytes.decode('utf-8')
|
196 |
else:
|
197 |
+
# Convert string salt to bytes
|
198 |
+
salt_bytes = salt.encode('utf-8')
|
199 |
|
200 |
+
# Hash the password
|
201 |
+
hashed = bcrypt.hashpw(password.encode('utf-8'), salt_bytes).decode('utf-8')
|
202 |
+
|
203 |
+
return hashed, salt
|
204 |
|
205 |
def verify_password(password: str, stored_hash: str, salt: str = None) -> bool:
|
206 |
"""Verify password against hash - supports both bcrypt and SHA256"""
|