I am currently making a python GUI with a login verification. I am using a text file to verify the login details. When I try to compare the userid and password against data from the file, it goes into the else condition and prints "Fail".
I am using tkinter for the GUI, but the login details do not work.
from tkinter import *
def verify_login():
file = open("login.txt","r")
for row in file:
field = row.split(",")
if username.get() == field[0] and password.get() == field[1]:
print("Correct!")
else:
print("Fail")
### LOGIN SCREEN ###
def LoginPage():
global username
global password
login_screen=Tk()
login_screen.title("Login")
login_screen.geometry("300x250")
Label(login_screen, text="Please enter login details").pack()
Label(login_screen, text="").pack()
Label(login_screen, text="Username").pack()
username=StringVar()
password=StringVar()
username_login = Entry(login_screen, textvariable=username)
username_login.pack()
Label(login_screen, text="").pack()
Label(login_screen, text="Password").pack()
password_login= Entry(login_screen, textvariable=password, show= '*')
password_login.pack()
Label(login_screen, text="").pack()
Button(login_screen, text="Login", width=10, height=1,command=verify_login).pack()
login_screen.mainloop(
### MAIN SCREEN ###
def Startpage():
global gui
gui=Tk(className="Login Form")
gui.geometry("500x200")
button = Button(gui, text='Login', width=20, height=3, bg='#0052cc', fg='#ffffff', activebackground='#0052cc', activeforeground='#aaffaa', command=LoginPage).pack()
gui.mainloop()
Startpage()
my text file has logins and passwords in this format:
login,a,yex,joe,morgan,1,sanjay,2