Spaces:
Sleeping
Sleeping
File size: 704 Bytes
0f82473 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import bcrypt
from src.utils.database import get_client
def verify_password(plain_password: str, hashed_password: str) -> bool:
return bcrypt.checkpw(plain_password.encode("utf-8"), hashed_password.encode("utf-8"))
def get_user(username: str) -> dict | None:
client = get_client()
response = (
client.table("users")
.select("id, username, password_hash, role")
.eq("username", username)
.execute()
)
return response.data[0] if response.data else None
def authenticate(username: str, password: str) -> dict | None:
user = get_user(username)
if user and verify_password(password, user["password_hash"]):
return user
return None
|