Login System with SQLite
This project is a simple user authentication system using Python. It demonstrates how to create a client-server architecture where a client can log in with a username and password. The credentials are stored securely in a SQLite database with password hashing for added security.
The purpose of this project is to showcase a basic implementation of user authentication using socket programming, threading, and a database in Python. It allows users to log in, verifying their credentials against stored data in a SQLite database.
The project consists of three main scripts:
- login_db.py: Sets up the SQLite database, creates a user table, and populates it with sample user credentials.
- server_db.py: Implements the server that listens for client connections, handles login requests, and validates user credentials against the database.
- client_db.py: Represents the client that connects to the server, sends username and password, and receives the login status.
- Python 3.x
- SQLite3
-
Run the Database Setup: First, execute
login_db.pyto create the SQLite database and populate it with sample users.python login_db.py
-
Start the Server: Run
server_db.pyto start the server that will handle client connections.python server_db.py
-
Run the Client: In a new terminal, execute
client_db.pyto start the client application.python client_db.py
-
Interact with the Client: Follow the prompts to enter the username and password. The client will send the credentials to the server, which will respond with either "Login Successful!" or "Login Failed!".
- Connects to the SQLite database and creates a
userdatatable if it doesn’t exist. - Hashes the passwords using SHA-256 and inserts sample users into the database.
- Creates a socket server that listens for incoming connections.
- Handles each connection in a separate thread using the
handle_connectionfunction. - Requests the username and password from the client, hashes the password, and checks the credentials against the database.
- Connects to the server and prompts the user for their username and password.
- Sends the credentials to the server and prints the server's response regarding the login status.
- Enter
mike123as the username andmikepasswordas the password to log in successfully. - Enter
wronguseror an incorrect password to see the "Login Failed!" message.
This project serves as an educational example of how to implement user authentication in Python using socket programming and SQLite. It can be extended with additional features such as password recovery, user registration, or more robust error handling.