Cs Project
Cs Project
1
INDEX
1 INTRODUCTION 3
2 OBJECTIVE 6
3
SCOPE 10
4
INPUT &OUTPUT REQUIREMENTS 14
5
FUNCTIONS & CLASSES 19
6
HARDWARE & SOFTWARE REQUIREMENTS 22
7
SOURCE CODE 25
8
OUTPUT 40
9
BIBLIOGRAPHY 46
2
INTRODUCTION
3
The "Login and Registration System" project is a
Python-based application that provides users with
a secure and user-friendly interface to register and
log into their accounts. Built using the tkinter
library for the graphical user interface and MySQL
as the backend database, this project offers
essential functionalities for user management and
authentication.
4
using Python and a MySQL database, making it an
excellent starting point for developing more
advanced applications with user accounts and
authentication features.
5
OBJECTIVE
6
Design, develop, and implement a robust and secure
login and registration system leveraging Tkinter, a
Python GUI library, and MySQL for database interaction.
The system aims to offer a seamless user experience by
providing functionalities for user registration, login
authentication, and administrative access to user
information.
Key Components and Features:
User Registration:
1. Enable users to register by inputting essential
details such as a unique username, a secure
password, a valid email address, gender
selection, and date of birth.
2. Implement robust validation checks to ensure
completeness and accuracy of user-provided
information. This includes checks for empty
fields, password matching, unique username
creation, and valid email formats.
3. Safeguard sensitive data such as passwords by
employing secure storage practices, like
hashing and salting, before storing them in the
database.
8
Database Interaction and Error Handling:
1. Establish a secure connection to the MySQL
database, handling potential connection errors
gracefully.
2. Implement error handling strategies for
database queries and transactions to mitigate
issues during user registration, login, or admin
data retrieval.
3. Log database-related errors for troubleshooting
purposes while providing informative error
messages to users.
9
SCOPE
10
Feature Enhancements:
1. Profile Management:
Allow users to update their profiles, change
passwords, or recover/reset forgotten
passwords.
Incorporate options for users to add additional
information or update existing details.
2. Two-Factor Authentication (2FA):
Implement an extra layer of security by
integrating two-factor authentication methods
(e.g., OTP via email or SMS) for user logins.
3. Social Login Integration:
Offer users the convenience of logging in using
their social media accounts (e.g., Google,
Facebook) as an alternative login method.
4. Email Verification for Registration:
Implement email verification to validate user
email addresses during registration, enhancing
security and ensuring the authenticity of users.
11
3. Real-Time Password Strength Checker:
Provide users with feedback on password
strength in real-time during registration to
encourage stronger passwords.
Security Measures:
1. Security Auditing and Testing:
Cond uct security audits and penetration testing
to identify and rectify potential vulnerabilities in
the system.
2. Enhanced Encryption Standards:
Upgrade encryption methods or adopt industry-
standard encryption protocols to strengthen
data security.
Admin Panel Enhancements:
3. Data Filtering and Sorting:
Enable admins to filter and sort user data based
on different parameters for better management
and analysis.
4. User Activity Tracking:
Implement a log system to track user activities,
login attempts, and critical actions performed
within the system for auditing purposes.
12
2. Cloud Integration:
Consider migrating to cloud-based solutions for
improved scalability, reliability, and
accessibility.
Compliance and Regulations:
1. GDPR and Data Privacy Compliance:
Ensure compliance with data privacy
regulations and standards, such as GDPR, by
implementing necessary measures for user
data protection.
2. Accessibility Compliance:
Ensure the system adheres to accessibility
standards (e.g., WCAG) to cater to users with
disabilities.
Continuous Maintenance and Support:
1. Bug Fixes and Updates:
Regularly address reported bugs and issues,
and provide updates to enhance system
stability and security.
2. User Support and Documentation:
Offer comprehensive documentation and user
support to assist users in utilizing the system
effectively.
13
INPUT & OUTPUT
REQUIREMENT
14
INPUT REQUIREMENT
Registration:
1. Username:
Requirement: Unique identifier for each user.
password.
Constraints: Should match the password
purposes.
Constraints: Valid email format (e.g.,
[email protected]).
5. Gender:
Requirement: Identification of the user's
gender.
Constraints: Selection between predefined
15
Login:
1. Username:
Requirement: Unique identifier for the
registered user.
Constraints: Alphanumeric characters, should
privileges.
Constraints: Unique identifier for the admin
account.
2. Admin Password:
Requirement: Secure access to admin
functionalities.
Constraints: Specific password associated with
16
OUTPUT REQUIREMENT
Registration Success Message: Upon successful
registration, the program displays a message confirming
the successful creation of the user account.
17
Database Connection Error Message: If there are
issues connecting to the MySQL database, the program
provides an error message to inform the user that the
database connection has failed.
Optional Password Visibility: The program allows
users to toggle the visibility of passwords (show/hide)
during registration and login for security and user
experience.
18
FUNCTIONS
&
CLASSES
19
Functions:
1. close_db_connection():
Purpose: Closes the connection to the MySQL
database and terminates the Tkinter window
when the user exits the application.
3. toggle_password_visibility_register() and
toggle_password_visibility_login():
Purpose: Control the visibility of passwords in
the registration and login frames respectively
based on a checkbox.
Details:
toggle_password_visibility_register(): Toggles
visibility of the registration password and repeat
password entries.
toggle_password_visibility_login(): Toggles
visibility of the login password entry.
4. display_user_info():
Purpose: Opens a new window showing user
information fetched from the database using a
Treeview widget.
20
Details:
Retrieves user information from the database and
displays it in a new window using a Treeview.
5. register():
Purpose: Manages the user registration
process.
Details:
Validates user input for registration.
Checks if the username already exists in the
database.
Inserts new user data into the database upon
successful validation.
6. login():
Purpose: Handles user login authentication.
Details:
Validates user input for login credentials.
Checks if the provided credentials match those
stored in the database.
Grants access if the credentials are valid.
7. clear_register_entries() and
clear_login_entries():
Purpose: Clears the entry fields in the
registration and login frames respectively.
Details:
clear_register_entries(): Clears all input fields
related to registration.
clear_login_entries(): Clears all input fields
related to login.
21
HARDWARE
&
SOFTWARE
REQUIREMENTS
22
HARDWARE REQUIREMENT
1. Computer or Device: The program can be run
on any modern computer or device capable of
running Python and a MySQL server.
23
SOFTWARE REQUIREMENT
1. Operating System: The program can run on
various operating systems, including:
Windows
macOS
Linux
2. Python: The program is developed in Python, so
you need a Python interpreter installed on your
system. It's recommended to use Python 3.7 or
later.
3. MySQL Database: You should have a MySQL
server installed and running on your system. You
can use MySQL Server or alternatives like
MariaDB. The database should have the necessary
tables and structure to store user data.
4. MySQL Connector for Python: You need the
MySQL connector for Python to interact with the
MySQL database.
5. Tkinter Library: Tkinter is used for the graphical
user interface (GUI). It's a standard library for
Python and comes pre-installed with most Python
distributions.
6. Text Editor or IDE: You can use any text editor
(e.g., Visual Studio Code, Sublime Text) or
integrated development environment (IDE) that you
prefer for writing and running Python code.
7. Database Management Tool (Optional): While not
strictly necessary, having a database management
tool like MySQL Workbench or phpMyAdmin can be
helpful for managing the MySQL database.
24
SOURCE CODE
25
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
import mysql.connector
def close_db_connection():
db.close()
window.destroy()
def switch_to_register():
welcome_label.config(text="Welcome - Register")
login_frame.pack_forget()
register_frame.pack()
clear_login_entries()
def switch_to_login():
welcome_label.config(text="Welcome - Login")
register_frame.pack_forget()
login_frame.pack()
clear_register_entries()
26
def toggle_password_visibility_register():
if show_password_var.get():
register_password_entry.config(show="")
repeat_password_entry.config(show="")
else:
register_password_entry.config(show="*")
repeat_password_entry.config(show="*")
def toggle_password_visibility_login():
if show_password_var_login.get():
login_password_entry.config(show="")
else:
login_password_entry.config(show="*")
def display_user_info():
user_info_window = tk.Toplevel(window)
user_info_window.title("User Information")
27
cursor.execute("SELECT * FROM users")
users = cursor.fetchall()
28
def register():
username = register_username_entry.get()
password = register_password_entry.get()
repeat_password = repeat_password_entry.get()
email = email_entry.get()
gender = gender_var.get()
day = day_entry.get()
month = month_entry.get()
year = year_entry.get()
dob = f"{year}-{month}-{day}"
29
if password != repeat_password:
messagebox.showerror("Error", "Passwords do not
match.")
return
try:
cursor.execute("SELECT * FROM users WHERE
username=%s", (username,))
if cursor.fetchone() is not None:
messagebox.showerror("Error", "Username already
exists.")
return
def login():
username = login_username_entry.get()
password = login_password_entry.get()
try:
31
cursor.execute("SELECT * FROM users WHERE
username=%s AND password=%s", (username,
password))
if cursor.fetchone() is not None:
messagebox.showinfo("Success", "Login successful.")
clear_login_entries()
else:
messagebox.showerror("Error", "Invalid login
credentials.")
except mysql.connector.Error as err:
print(f"Error: {err}")
messagebox.showerror("Database Error", "Failed to log
in. Please try again.")
def clear_register_entries():
register_username_entry.delete(0, tk.END)
register_password_entry.delete(0, tk.END)
repeat_password_entry.delete(0, tk.END)
email_entry.delete(0, tk.END)
gender_var.set("")
32
day_entry.delete(0, tk.END)
month_entry.delete(0, tk.END)
year_entry.delete(0, tk.END)
def clear_login_entries():
login_username_entry.delete(0, tk.END)
login_password_entry.delete(0, tk.END)
window = tk.Tk()
window.title("Login and Registration System")
window.geometry("400x500")
try:
db = mysql.connector.connect(
host="localhost",
user="root",
password="sathya123",
database="project"
)
33
cursor = db.cursor()
except mysql.connector.Error as err:
print(f"Error: {err}")
messagebox.showerror("Database Error", "Failed to
connect to the database. Check your database settings.")
window.protocol("WM_DELETE_WINDOW",
close_db_connection)
register_frame = tk.Frame(window)
login_frame = tk.Frame(window)
register_username_label = tk.Label(register_frame,
text="Username")
register_username_label.pack()
register_username_entry = tk.Entry(register_frame)
register_username_entry.pack()
34
register_password_label = tk.Label(register_frame,
text="Password")
register_password_label.pack()
register_password_entry = tk.Entry(register_frame,
show="*")
register_password_entry.pack()
repeat_password_label = tk.Label(register_frame,
text="Repeat Password")
repeat_password_label.pack()
repeat_password_entry = tk.Entry(register_frame, show="*")
repeat_password_entry.pack()
gender_var = tk.StringVar()
gender_label = tk.Label(register_frame, text="Gender")
35
gender_label.pack()
male_radio = tk.Radiobutton(register_frame, text="Male",
variable=gender_var, value="Male")
female_radio = tk.Radiobutton(register_frame,
text="Female", variable=gender_var, value="Female")
male_radio.pack()
female_radio.pack()
show_password_var = tk.BooleanVar()
show_password_check = tk.Checkbutton(register_frame,
text="Show Password", variable=show_password_var,
command=toggle_password_visibility_register)
show_password_check.pack()
login_username_label = tk.Label(login_frame,
text="Username")
login_username_label.pack()
login_username_entry = tk.Entry(login_frame)
login_username_entry.pack()
login_password_label = tk.Label(login_frame,
text="Password")
37
login_password_label.pack()
login_password_entry = tk.Entry(login_frame, show="*")
login_password_entry.pack()
show_password_var_login = tk.BooleanVar()
show_password_check_login = tk.Checkbutton(login_frame,
text="Show Password",
variable=show_password_var_login002C
command=toggle_password_visibility_login)
show_password_check_login.pack()
38
register_option = tk.Label(login_frame, text="New user?
Register here.", cursor="hand2", fg="blue")
register_option.bind("<Button-1>", lambda e:
switch_to_register())
login_button.pack()
register_option.pack()
switch_to_register()
window.mainloop()
39
OUTPUT
40
41
42
43
44
45
BIBLIOGRAPHY
46
1. https://www.google.com/
2. https://chat.openai.com/
3. https://www.bing.com/
4. https://www.python.org/
5. https://www.w3schools.com/
6. https://www.onlinegdb.com/
47