0% found this document useful (0 votes)
6 views

Cs Project

Uploaded by

hariplasticsgk
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Cs Project

Uploaded by

hariplasticsgk
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

ACKNOWLEDGMENT

I would like to express my sincere gratitude to our


principal Rev Bro. Robert Lourdusamy our
Vice-Principal Rev Bro. Christuraja for helping
us with providing all the equipment’s for the
project work and for moral support and also to my
computer teacher Mr. John Stephen for giving us
the wonderful opportunity to do a case study and
providing vital support , guidance and
encouragement throughout the project. Without his
motivation and help, the successful completion for
this project would not be possible.

Secondly I would like to thank my friends who


helped me a lot in finalizing this project within the
limited time frame.

1
INDEX

S.NO. TOPIC PAGE NO.

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.

Users can register by providing their desired


username, password, email, gender, and date of
birth. The system ensures data integrity by
verifying that passwords match and that the
username is unique. In the event of an error or
failed registration, the application provides
informative error messages to guide users through
the process.

For registered users, the login functionality


ensures secure access to their accounts. If an
administrator account is used (username: "admin,"
password: "admin123"), the system offers the
capability to display user information in a separate
window.

The "Login and Registration System" project is a


practical demonstration of how to create a basic
authentication and user management system

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.

 User Authentication and Login:


1. Allow registered users to log in securely using
their unique username and password
combination.
2. Implement authentication protocols to validate
user credentials against stored data in the
database, ensuring only authorized users gain
access.
7
3. Incorporate error handling mechanisms to notify
users of incorrect login attempts or invalid
credentials without disclosing sensitive
information.

 Admin Access for User Information:


1. Provide an administrative login option (e.g., an
admin username/password) with elevated
privileges to access user information stored in
the database.
2. Display user information in a structured format,
allowing admins to view user IDs, usernames,
emails, genders, and dates of birth.
3. Ensure that only authorized admin credentials
grant access to this sensitive user information.

 Graphical User Interface (GUI):


1. Create an intuitive and user-friendly interface
using Tkinter, offering clear navigation between
registration and login frames.
2. Incorporate visual cues for password visibility
toggling to enhance user experience during
password entry.
3. Ensure consistent and informative feedback via
pop-up message boxes (using messagebox)
for successful actions or encountered errors
throughout the user interaction.

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.

 Optimization and Scalability:


1. Optimize code structure and database queries
for efficiency and scalability, ensuring smooth
system performance even with increased user
data or concurrent user interactions.
2. Design the system to allow for potential future
enhancements or feature additions while
maintaining its integrity and security measures.

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.

User Experience Improvements:


1. Responsive Design:
 Optimize the GUI for responsiveness across
different devices and screen sizes, ensuring a
consistent user experience.
2. Enhanced UI/UX:
 Refine the user interface with improved visuals,
user-friendly layouts, and intuitive navigation for
a more engaging experience.

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.

Scalability and Performance:


1. Caching Mechanisms:
 Implement caching strategies to improve
system performance, especially during high
traffic or frequent database queries.

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.

 Constraints: Alphanumeric characters, unique

among registered usernames.


2. Password:
 Requirement: Secure access to the account.

 Constraints: Minimum length, typically including

a mix of uppercase, lowercase, numbers, and


special characters for enhanced security.
3. Repeat Password:
 Requirement: Confirmation of the entered

password.
 Constraints: Should match the password

entered for validation.


4. Email:
 Requirement: Contact and communication

purposes.
 Constraints: Valid email format (e.g.,

[email protected]).
5. Gender:
 Requirement: Identification of the user's

gender.
 Constraints: Selection between predefined

options (e.g., Male, Female).


6. Date of Birth (DOB):
 Requirement: Verification of user's age.

 Constraints: Input of the day, month, and year

components to form a valid date.

15
Login:
1. Username:
 Requirement: Unique identifier for the

registered user.
 Constraints: Alphanumeric characters, should

match a registered username.


2. Password:
 Requirement: Access to the user's account.

 Constraints: Should match the password

associated with the entered username for


authentication.
Admin Access:
1. Admin Username:
 Requirement: Special access for administrative

privileges.
 Constraints: Unique identifier for the admin

account.
2. Admin Password:
 Requirement: Secure access to admin

functionalities.
 Constraints: Specific password associated with

the admin account for elevated access.

16
OUTPUT REQUIREMENT
Registration Success Message: Upon successful
registration, the program displays a message confirming
the successful creation of the user account.

Registration Error Messages: In case of registration


errors, the program provides informative error messages
to guide the user. These error messages may include:
A message indicating that all required fields must be
filled out.
A message notifying the user that the passwords
provided during registration do not match.
A message indicating that the chosen username already
exists.

Login Success Message: Upon successful login, the


program displays a message confirming a successful
login attempt and provides access to the user's account.

Login Error Messages: In the event of login failures,


the program provides clear error messages to inform the
user of the issue. These error messages may include:
A message indicating that both the username and
password are required fields.
A message informing the user of invalid login
credentials.

User Information Display: For administrators who


successfully log in using the provided admin credentials,
the program opens a separate window displaying user
information retrieved from the MySQL database.

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.

These output requirements ensure that the program


communicates effectively with the user, providing
feedback on the success or failure of registration and
login actions and delivering necessary information in a
clear and user-friendly manner.

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.

2. switch_to_register() and switch_to_login():


 Purpose: Toggle between the registration and
login frames within the main window.
 Details:
switch_to_register(): Displays the registration
frame, hiding the login frame.
switch_to_login(): Displays the login frame,
hiding the registration frame.

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.

2. Processor: A standard processor (e.g., Intel Core


or AMD Ryzen) is sufficient for running the program.

3. Memory (RAM): A minimum of 2GB of RAM is


recommended for smooth execution, but more RAM
can improve overall performance.

4. Storage: The program itself doesn't require much


storage space, but you need enough storage for the
MySQL database, especially if you plan to store a
large amount of user data.

5. Input Devices: A keyboard and mouse (or


touchpad) for user interaction with the graphical
interface.

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()

user_info_label = tk.Label(user_info_window, text="User


Information", font=("Helvetica", 16))
user_info_label.pack()

tree = ttk.Treeview(user_info_window, columns=("User


ID", "Username", "Email", "Gender", "Date of Birth"))
tree.heading("#1", text="User ID")
tree.heading("#2", text="Username")
tree.heading("#3", text="Email")
tree.heading("#4", text="Date of Birth")
tree.heading("#5", text="Gender")
tree.pack()

for user in users:


tree.insert("", "end", values=(user[0], user[1], user[3],
user[5], user[4]))

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}"

if not (username and password and repeat_password and


email and gender and day and month and year):
messagebox.showerror("Error", "All fields are required.")
return

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

cursor.execute("INSERT INTO users (username,


password, email, gender, dob) VALUES (%s, %s, %s, %s,
%s)",(username, password, email, gender, dob))
db.commit()
messagebox.showinfo("Success", "Registration
successful.")
clear_register_entries()
30
except mysql.connector.Error as err:
print(f"Error: {err}")
messagebox.showerror("Database Error", "Failed to
register the user. Please try again.")

def login():
username = login_username_entry.get()
password = login_password_entry.get()

if not (username and password):


messagebox.showerror("Error", "Both fields are
required.")
return

if username == "admin" and password == "admin123":


display_user_info()
clear_login_entries()
return

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)

welcome_label = tk.Label(register_frame, text="Welcome -


Register", font=("Helvetica", 20))
welcome_label.pack()

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()

email_label = tk.Label(register_frame, text="Email")


email_label.pack()
email_entry = tk.Entry(register_frame)
email_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()

dob_label = tk.Label(register_frame, text="Date of Birth


(DOB)")
dob_label.pack()
day_label = tk.Label(register_frame, text="Day")
day_label.pack()
day_entry = tk.Entry(register_frame)
day_entry.pack()
month_label = tk.Label(register_frame, text="Month")
month_label.pack()
month_entry = tk.Entry(register_frame)
month_entry.pack()
year_label = tk.Label(register_frame, text="Year")
year_label.pack()
36
year_entry = tk.Entry(register_frame)
year_entry.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()

welcome_label_login = tk.Label(login_frame, text="Welcome


- Login", font=("Helvetica", 20))
welcome_label_login.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()

register_button = tk.Button(register_frame, text="Register",


command=register)
login_option = tk.Label(register_frame, text="Already
registered? Login here.", cursor="hand2", fg="blue")
login_option.bind("<Button-1>", lambda e: switch_to_login())
register_button.pack()
login_option.pack()

login_button = tk.Button(login_frame, text="Login",


command=login)

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

You might also like