19 lines
551 B
Python
19 lines
551 B
Python
from datetime import datetime, timezone
|
|
from hashlib import sha256
|
|
|
|
from backend.app.database import get_connection
|
|
|
|
|
|
def hash_password(password: str) -> str:
|
|
return sha256(password.encode('utf-8')).hexdigest()
|
|
|
|
|
|
def authenticate_user(username: str, password: str):
|
|
password_hash = hash_password(password)
|
|
with get_connection() as conn:
|
|
row = conn.execute(
|
|
'SELECT * FROM users WHERE username = ? AND password_hash = ?',
|
|
(username, password_hash),
|
|
).fetchone()
|
|
return dict(row) if row else None
|