Spaces:
Sleeping
Sleeping
Download src/utils/auth.py from jayanth-2005/1: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/jayanth-2005/1/resolve/main/src/utils/auth.py
- Command line
-
hf download hf://spaces/jayanth-2005/1/src/utils/auth.py
-
curl -L -o auth.py https://huggingface.co/spaces/jayanth-2005/1/resolve/main/src/utils/auth.py
1.19 kB
| import sqlite3 | |
| import hashlib | |
| import os | |
| DB_PATH = os.path.join(os.path.dirname(__file__), "..", "bharat_play.db") # Bundled DB path | |
| def init_db(): | |
| pass # DB is prebuilt and bundled | |
| def get_connection(): | |
| return sqlite3.connect(DB_PATH) | |
| def hash_password(password): | |
| return hashlib.sha256(password.encode()).hexdigest() | |
| def login_user(username, password): | |
| conn = get_connection() | |
| try: | |
| c = conn.cursor() | |
| hashed_pw = hash_password(password) | |
| c.execute('SELECT * FROM users WHERE username=? AND password=?', | |
| (username, hashed_pw)) | |
| return c.fetchone() is not None | |
| finally: | |
| conn.close() | |
| def signup_user(username, password): | |
| if not username or not password: | |
| return False | |
| conn = get_connection() | |
| try: | |
| c = conn.cursor() | |
| hashed_pw = hash_password(password) | |
| c.execute("INSERT INTO users (username, password) VALUES (?, ?)", (username, hashed_pw)) | |
| conn.commit() | |
| return True | |
| except sqlite3.IntegrityError: | |
| return False | |
| except Exception as e: | |
| print(f"Error during signup: {e}") | |
| return False | |
| finally: | |
| conn.close() | |