Oct-19-2020, 05:08 PM
So I tried creating a basic login system in python since im just trying it to get a grasp of the language. Im using a txt file to save multiple usernames and passwords in it, while also making use of the tkinter library for a GUI. The user and password are always stored respectively above and below each other. When I got to the stage where I started coding the comparison between an input and the stored user/password i ran into the issue that for some reason when comparing the 2 strings in an if condition they never fit together. Even when I printed the 2 strings just before the condition and the console confirmed they were the same they never change the condition to true.
Maybe its just me thats missing some obvious stuff but I hope someone can give me a plausible answer for this.
Maybe its just me thats missing some obvious stuff but I hope someone can give me a plausible answer for this.
from tkinter import * import time def getEntryInput(): Input_User = USER.get() Input_Pass = PASS.get() UserList = open("User.txt", "r") RegisteredUsernames = UserList.readlines() a = 0 for x in RegisteredUsernames: if Input_User == x: if Input_Pass == RegisteredUsernames[(a+1)]: SuccessLabel.configure(text="Success") break else: SuccessLabel.configure(text="Wrong") else: SuccessLabel.configure(text="Wrong") a = a + 1 UserList.close() def RegNewUser(): RegWindow = Toplevel() RegWindow.geometry("200x200") RegWindow.title("Register") RegTitleLabel = Label(RegWindow, text="Register new user") RegTitleLabel.pack() RegUSER = Entry(RegWindow) RegPASS = Entry(RegWindow) RegUSER.insert(0, "Username") RegPASS.insert(0, "Password") RegUSER.pack() RegPASS.pack() root = Tk() root.geometry("400x300") titlelabel = Label(root, text="Please Enter User and Password") SuccessLabel = Label(root) LogButton = Button(root, text="Login", command=getEntryInput) RegButton = Button(root, text="Register new user", command=RegNewUser) USER = Entry(root) PASS = Entry(root) USER.insert(0, "Username") PASS.insert(0, "Password") titlelabel.pack() SuccessLabel.pack() USER.pack() PASS.pack() LogButton.place(x=150, y=100, height=50, width=100) RegButton.place(x=150, y=150, height=50, width=100) root.title("Login") root.mainloop()