Skip to content

Commit f418a5c

Browse files
Merge pull request #1571 from HartzFrequency/master
[GSSoC 23'] GUI Login Page Addition with credential checking mechanism
2 parents 03ee3c5 + 9930686 commit f418a5c

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## SIGN UP GUI PAGE
2+
3+
To run the code, you need to specify the file paths where the username and password will be stored in a .txt format. Once you have set the file paths correctly, you can simply run the program.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import tkinter as tk
2+
import tkinter.messagebox
3+
from tkinter import PhotoImage
4+
from tkinter import messagebox
5+
from tkinter.font import Font
6+
import customtkinter
7+
from PIL import Image, ImageTk
8+
9+
customtkinter.set_appearance_mode("dark")
10+
11+
def check_credentials(username, password):
12+
# Read the stored usernames and passwords from text files
13+
with open('File Path Where username is stored', 'r') as f_username, open('File Path where password is stored', 'r') as f_password:
14+
stored_usernames = f_username.read().splitlines()
15+
stored_passwords = f_password.read().splitlines()
16+
17+
# Check if the entered credentials match any of the stored values
18+
for stored_username, stored_password in zip(stored_usernames, stored_passwords):
19+
if username == stored_username and password == stored_password:
20+
return True
21+
22+
return False
23+
24+
25+
class Login(customtkinter.CTk):
26+
width = 1240 #helps in image width
27+
height = 1080 #helps in image height
28+
def __init__(self):
29+
super().__init__()
30+
31+
# OPENEING WINDOW SIZE
32+
self.title("Login")
33+
self.geometry(f"{1240}x{720}")
34+
# IMAGE ADDITION IN BACKGROUND
35+
# self.bg_image = customtkinter.CTkImage(Image.open("Image Path"),size=(self.width, self.height))
36+
# self.bg_image_label = customtkinter.CTkLabel(self, image=self.bg_image)
37+
# self.bg_image_label.grid(row=0, column=0)
38+
39+
# LOGIN FRAME INSIDE WINDOW
40+
# TEXT : "Welcome!\nUnified Travelling & Transport System"
41+
self.login_frame = customtkinter.CTkFrame(self, corner_radius=15)
42+
self.login_frame.grid(row=0, column=0, sticky="ns")
43+
self.login_label = customtkinter.CTkLabel(self.login_frame, text="Welcome!\nTo lOIGN pAGE",font=customtkinter.CTkFont(size=24, weight="bold", slant="roman", family="Helvetica"))
44+
self.login_label.grid(row=0, column=0, padx=30, pady=(150, 15))
45+
46+
#TEXT : LOGIN PAGE
47+
self.login_label_2 = customtkinter.CTkLabel(self.login_frame, text="Login Page",font=customtkinter.CTkFont(size=40, weight="bold"))
48+
self.login_label_2.grid(row=1, column=0, padx=30, pady=(50, 15))
49+
50+
#TEXT : USERNAME
51+
self.username_entry = customtkinter.CTkEntry(self.login_frame, width=300, placeholder_text="Username")
52+
self.username_entry.grid(row=2, column=0, padx=30, pady=(15, 15))
53+
54+
#TEXT : PASSWORD
55+
self.password_entry = customtkinter.CTkEntry(self.login_frame, width=300, show="*", placeholder_text="Password")
56+
self.password_entry.grid(row=3, column=0, padx=30, pady=(0, 15))
57+
58+
#TEXT : LOGIN BUTTON TEXT
59+
self.login_button = customtkinter.CTkButton(self.login_frame, text="Login", command=self.login_event, width=200)
60+
self.login_button.grid(row=4, column=0, padx=30, pady=(15, 15))
61+
62+
def login_event(self):
63+
64+
entered_username = self.username_entry.get()
65+
entered_password = self.password_entry.get()
66+
67+
QueryCheckForPassword=sql.Query_LoginCheck(entered_username, entered_password)
68+
69+
if QueryCheckForPassword:
70+
self.destroy()
71+
72+
else:
73+
print("error")
74+
return messagebox.showerror('Error','Incorrect Username or Password')
75+
76+
print("Login pressed - username:", entered_username, "password:",entered_password)
77+
78+
if __name__ == "__main__":
79+
app9 = Login()
80+
app9.mainloop()

0 commit comments

Comments
 (0)