ciyidogan commited on
Commit
76adea2
·
verified ·
1 Parent(s): dbf4dea

Update admin_routes.py

Browse files
Files changed (1) hide show
  1. admin_routes.py +13 -4
admin_routes.py CHANGED
@@ -195,10 +195,19 @@ def hash_password(password: str, salt: str = None) -> tuple[str, str]:
195
  hashed = bcrypt.hashpw(password.encode('utf-8'), salt).decode('utf-8')
196
  return hashed, salt.decode('utf-8') if isinstance(salt, bytes) else salt
197
 
198
- def verify_password(password: str, hashed: str, salt: str) -> bool:
199
- """Verify password against hash"""
200
- return bcrypt.checkpw(password.encode('utf-8'), hashed.encode('utf-8'))
201
-
 
 
 
 
 
 
 
 
 
202
  def load_config() -> Dict[str, Any]:
203
  """Load service_config.jsonc"""
204
  config_path = Path("service_config.jsonc")
 
195
  hashed = bcrypt.hashpw(password.encode('utf-8'), salt).decode('utf-8')
196
  return hashed, salt.decode('utf-8') if isinstance(salt, bytes) else salt
197
 
198
+ def verify_password(password: str, stored_hash: str, salt: str = None) -> bool:
199
+ """Verify password against hash - supports both bcrypt and SHA256"""
200
+ # First try bcrypt
201
+ if salt and len(stored_hash) == 60: # bcrypt hash length
202
+ try:
203
+ return bcrypt.checkpw(password.encode('utf-8'), stored_hash.encode('utf-8'))
204
+ except:
205
+ pass
206
+
207
+ # Fallback to SHA256 for backward compatibility
208
+ sha256_hash = hashlib.sha256(password.encode()).hexdigest()
209
+ return sha256_hash == stored_hash
210
+
211
  def load_config() -> Dict[str, Any]:
212
  """Load service_config.jsonc"""
213
  config_path = Path("service_config.jsonc")