Spaces:
Sleeping
Sleeping
suhail commited on
Commit ·
ae8175d
1
Parent(s): 87b35fd
good
Browse files- src/core/security.py +20 -6
src/core/security.py
CHANGED
|
@@ -147,14 +147,28 @@ def hash_password(password: str) -> str:
|
|
| 147 |
|
| 148 |
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
| 149 |
"""
|
| 150 |
-
Verify password
|
| 151 |
-
NEVER crashes.
|
| 152 |
"""
|
| 153 |
try:
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
except Exception:
|
| 159 |
return False
|
| 160 |
|
|
|
|
| 147 |
|
| 148 |
def verify_password(plain_password: str, hashed_password: str) -> bool:
|
| 149 |
"""
|
| 150 |
+
Verify password with AUTO migration from legacy hashes.
|
|
|
|
| 151 |
"""
|
| 152 |
try:
|
| 153 |
+
# New method (SHA256 → bcrypt)
|
| 154 |
+
normalized = hashlib.sha256(
|
| 155 |
+
plain_password.encode("utf-8")
|
| 156 |
+
).digest()
|
| 157 |
+
|
| 158 |
+
if pwd_context.verify(normalized, hashed_password):
|
| 159 |
+
return True
|
| 160 |
+
|
| 161 |
+
except Exception:
|
| 162 |
+
pass
|
| 163 |
+
|
| 164 |
+
# 🔁 Legacy fallback (OLD system)
|
| 165 |
+
try:
|
| 166 |
+
legacy = hashlib.sha256(
|
| 167 |
+
plain_password.encode("utf-8")
|
| 168 |
+
).hexdigest()
|
| 169 |
+
|
| 170 |
+
return pwd_context.verify(legacy, hashed_password)
|
| 171 |
+
|
| 172 |
except Exception:
|
| 173 |
return False
|
| 174 |
|