This project demonstrates the implementation of a simple user registration, login, and account removal system using Python 3.11 with a MySQL/MariaDB database. The system uses Object-Oriented Programming (OOP) principles and the MVC (Model-View-Controller) architecture. It utilizes the SQLAlchemy ORM to interact with the database, ensuring modularity and code reuse.
- Python 3.11: The primary programming language.
- MySQL / MariaDB: The relational database system used to store user data.
- SQLAlchemy: An Object-Relational Mapper (ORM) for managing database interactions.
- PyMySQL: A library used by SQLAlchemy to interact with MySQL/MariaDB databases.
- MVC Architecture: The project follows the Model-View-Controller design pattern for better organization and separation of concerns.
-
MySQL/MariaDB:
- Ensure MySQL/MariaDB is installed on your machine.
- Create the database with the following command:
CREATE DATABASE registration_and_login;
-
Install Dependencies:
- Install the required libraries using pip:
pip install sqlalchemy pymysql
- Install the required libraries using pip:
-
model.py
:- Defines the database structure and ORM mappings using SQLAlchemy.
- Contains the
Person
class, representing user data in the database.
-
controller.py
:- Contains the
RegisterController
,LoginController
, andRemoveController
classes responsible for handling user registration, login, and account removal. - The controllers interact with the database through the SQLAlchemy session to perform CRUD operations.
- Contains the
-
view.py
:- Acts as the user interface, providing a simple menu for the user to choose between registration, login, or account removal.
- Collects user inputs and passes them to the appropriate controller for processing.
In the model.py
file, update the following connection parameters to match your database setup:
USER = 'root' # Your MySQL/MariaDB username
PASSWORD = '123456' # Your MySQL/MariaDB password
HOST = 'localhost' # The host where MySQL/MariaDB is running
PORT = '3306' # The port MySQL/MariaDB is listening on
DATABASE = 'registration_and_login' # The name of the database
- Running the Application
To run the application, execute view.py:
python view.py
This will present a menu where you can choose one of the following options:
1: Register a new user.
2: Login with an existing user.
3: Remove a user account.
4: Exit the application.
-
Registration Flow
The user will be prompted to enter a name, email, and password. The system checks the validity of the entered data (name, email, and password length validation). If the data is valid, the user is added to the person table in the database with the password hashed.
-
Login Flow
The user enters their email and password. The system checks if the email and password match an existing user in the database. If successful, the user is logged in.
-
Remove Account Flow
The user can remove their account by providing the email of the account they wish to delete. The system checks if the email exists in the database and removes the user if found.
Key Features
Data Validation: Ensures that user inputs are within acceptable limits (e.g., name, email, and password lengths).
Password Hashing: Passwords are hashed using SHA-256 before being stored in the database.
Modular Structure: The project is divided into separate files for better organization: model.py (database), controller.py (business logic), and view.py (user interface).
Session Management: SQLAlchemy is used to manage sessions and interact with the database.
Python 3.11
MySQL or MariaDB
SQLAlchemy
PyMySQL