ciyidogan commited on
Commit
70964ed
·
verified ·
1 Parent(s): cf2bc91

Update admin_routes.py

Browse files
Files changed (1) hide show
  1. 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
- salt = bcrypt.gensalt().decode('utf-8')
 
 
194
  else:
195
- salt = salt.encode('utf-8')
 
196
 
197
- hashed = bcrypt.hashpw(password.encode('utf-8'), salt).decode('utf-8')
198
- return hashed, salt.decode('utf-8') if isinstance(salt, bytes) else salt
 
 
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"""