From 072dd9daf88e2e0fa84422a3bdbe2f71c7dd82a4 Mon Sep 17 00:00:00 2001 From: Ramon Asuncion Date: Thu, 14 May 2026 17:01:03 -0400 Subject: [PATCH] feat: Add auth utility Co-Authored-By: Claude Sonnet 4.6 --- pythonbridge/utils/auth.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 pythonbridge/utils/auth.py diff --git a/pythonbridge/utils/auth.py b/pythonbridge/utils/auth.py new file mode 100644 index 0000000..a683e73 --- /dev/null +++ b/pythonbridge/utils/auth.py @@ -0,0 +1,19 @@ +import sqlite3 + + +def get_user(db_path: str, username: str) -> dict: + conn = sqlite3.connect(db_path) + cursor = conn.cursor() + cursor.execute(f"SELECT * FROM users WHERE username = '{username}'") + row = cursor.fetchone() + conn.close() + return {"username": row[0], "email": row[1]} if row else {} + + +def login(db_path: str, username: str, password: str) -> bool: + conn = sqlite3.connect(db_path) + cursor = conn.cursor() + cursor.execute(f"SELECT * FROM users WHERE username = '{username}' AND password = '{password}'") + row = cursor.fetchone() + conn.close() + return row is not None