Download utils.py from AhmedShahan/JobSathi_Backend: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/AhmedShahan/JobSathi_Backend/resolve/main/utils.py
- Command line
-
hf download hf://spaces/AhmedShahan/JobSathi_Backend/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/AhmedShahan/JobSathi_Backend/resolve/main/utils.py
1.02 kB
| import os | |
| import psycopg2 | |
| from argon2 import PasswordHasher | |
| from dotenv import load_dotenv | |
| # Load variables from .env file | |
| load_dotenv() | |
| DB_HOST = os.getenv("DB_HOST") | |
| DB_PORT = os.getenv("DB_PORT") | |
| DB_NAME = os.getenv("DB_NAME") | |
| DB_USER = os.getenv("DB_USER") | |
| DB_PASSWORD = os.getenv("DB_PASSWORD") | |
| _hasher = PasswordHasher() | |
| def get_connection(): | |
| """Open a new connection to the Supabase Postgres database.""" | |
| return psycopg2.connect( | |
| host=DB_HOST, | |
| port=DB_PORT, | |
| dbname=DB_NAME, | |
| user=DB_USER, | |
| password=DB_PASSWORD, | |
| ) | |
| def hash_password(password: str) -> str: | |
| """Return an Argon2 hash string for the given plaintext password.""" | |
| return _hasher.hash(password) | |
| def verify_password(password: str, hashed: str) -> bool: | |
| """Verify a plaintext password against an Argon2 hash string. | |
| Returns False on mismatch or invalid hash; never raises. | |
| """ | |
| try: | |
| return _hasher.verify(hashed, password) | |
| except Exception: | |
| return False |