| | import sqlite3 |
| |
|
| | |
| | conn = sqlite3.connect("users.db") |
| | cursor = conn.cursor() |
| |
|
| | |
| | cursor.execute("CREATE TABLE IF NOT EXISTS users (username text, password text)") |
| |
|
| | |
| | def signup(): |
| | |
| | username = input("Enter a username: ") |
| | password = input("Enter a password: ") |
| | |
| | cursor.execute("INSERT INTO users (username, password) VALUES (?, ?)", (username, password)) |
| | conn.commit() |
| | print("Signup successful!") |
| |
|
| | |
| | def login(): |
| | |
| | username = input("Enter your username: ") |
| | password = input("Enter your password: ") |
| | |
| | cursor.execute("SELECT * FROM users WHERE username=? AND password=?", (username, password)) |
| | if cursor.fetchone() is not None: |
| | print("Login successful!") |
| | else: |
| | print("Invalid username or password. Please try again.") |
| |
|
| | |
| | while True: |
| | choice = input("Would you like to signup or login? (s/l) ") |
| | if choice == 's': |
| | signup() |
| | elif choice == 'l': |
| | login() |
| | else: |
| | print("Invalid choice. Please try again.") |
| |
|
| | |
| | conn.close() |
| |
|