My friend and I are making a program that requires a login. We managed to force the user to enter detailed information and create a program to create a text file with the name (username) with detailed information. Each of them is formatted as follows:
(Name)
(Username)
(Password)
when you want to log in, the program asks for your name and finds a file with the name (no matter what they typed). if it exists, the program opens a GUI window and asks for a username and password, and if you enter the correct information about the file that opens, it says that the data is incorrect. We think this is due to variables, but we tried many different ways to lay etc and cannot find the problem. Can anyone help? (The code I included is just part of the GUI, including a bit that doesn't work, the rest is ok.
def LogIn():
name=input("Please enter your name: ")
file = open(name.lower() + " profile.txt", "r")
import tkinter
import time
window = tkinter.Tk()
window.title("Python Games Login")
window.geometry("270x210")
window.wm_iconbitmap("Login icon.ico")
window.configure(bg="#39d972")
def callback():
line = file.readlines()
username = user.get()
password = passw.get()
if username == line[1] and password == line[2]:
message.configure(text = "Logged in.")
else:
message.configure(text = "Username and password don't match the account \n under the name;\n \'" + name + "\'. \nPlease try again.")
title1 = tkinter.Label(window, text="--Log in to play the Python Games--\n", bg="#39d972")
usertitle = tkinter.Label(window, text="---Username---", bg="#39d972")
passtitle = tkinter.Label(window, text="---Password---", bg="#39d972")
message = tkinter.Label(window, bg="#39d972")
user = tkinter.Entry(window)
passw = tkinter.Entry(window, show='*')
go = tkinter.Button(window, text="Log in!", command = callback, bg="#93ff00")
title1.pack()
usertitle.pack()
user.pack()
passtitle.pack()
passw.pack()
go.pack()
message.pack()
window.mainloop()
source
share