added password hashing and ensured admin user exists
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""Password hashing utilities using bcrypt."""
|
||||
|
||||
import bcrypt
|
||||
|
||||
|
||||
def hash_password(password: str) -> str:
|
||||
"""Hash a password using bcrypt.
|
||||
|
||||
Args:
|
||||
password: Plain text password to hash
|
||||
|
||||
Returns:
|
||||
Hashed password as a string
|
||||
"""
|
||||
salt = bcrypt.gensalt()
|
||||
hashed: bytes = bcrypt.hashpw(password.encode("utf-8"), salt)
|
||||
return hashed.decode("utf-8")
|
||||
|
||||
|
||||
def verify_password(password: str, hashed_password: str) -> bool:
|
||||
"""Verify a password against a hashed password.
|
||||
|
||||
Args:
|
||||
password: Plain text password to verify
|
||||
hashed_password: Previously hashed password
|
||||
|
||||
Returns:
|
||||
True if password matches, False otherwise
|
||||
"""
|
||||
result: bool = bcrypt.checkpw(
|
||||
password.encode("utf-8"), hashed_password.encode("utf-8")
|
||||
)
|
||||
return result
|
||||
Reference in New Issue
Block a user