J.kors J.kors - 3 years ago 109
Python Question

Python Tkinter GUI User Login Accepting any Username with Correct Password

Alright so I must be missing something silly or obvious here but I have created this method to check for a username and password inside of my GUI and it just does some weird things. I can type in any username but as long as the password is correct, it will accept it. I have looked at the other similar questions but haven't seen an answer that accounts for my issue. Does anyone see what I'm doing wrong here? Thanks

def correct_login(text):
stored_user = user_entry.get()
if stored_user == "admin" or "ADMIN":
stored_pass = pass_entry.get()
if stored_pass == "password":
user_entry.delete(0, 'end')
pass_entry.delete(0, 'end')
pass_win.destroy()
else:
user_entry.delete(0, 'end')
pass_entry.delete(0, 'end')
mb.showwarning("Incorrect Credentials", "The username or password you have entered are incorrect.")
else:
user_entry.delete(0, 'end')
pass_entry.delete(0, 'end')
mb.showwarning("Incorrect Credentials", "The username or password you have entered are incorrect.")

pass_win.bind('<Return>',correct_login)

user_label = tk.Label(pass_win, text="Username", font=("Helvetica", 16))
user_entry = tk.Entry(pass_win)
pass_label = tk.Label(pass_win, text="Password", font=("Helvetica", 16))
pass_entry = tk.Entry(pass_win, show="*")

user_label.grid(row=1, column=0, sticky="E", padx=20, pady=10)
user_entry.grid(row=1, column=1, sticky="W", padx=20, pady=10)
pass_label.grid(row=2, column=0, sticky="E", padx=20, pady=10)
pass_entry.grid(row=2, column=1, sticky="W", padx=20, pady=10)

user_entry.focus_force()

submit_button = tk.Button(pass_win, text="Submit", command=correct_login)
submit_button.grid(row=3, column=0, sticky=("N", "S", "E", "W"), padx=20, columnspan=2)
quit_button = tk.Button(pass_win, text="Quit", command=pass_win.destroy)
quit_button.grid(row=4, column=0, sticky=("N", "S", "E", "W"), padx=20, columnspan=2)

user_entry.delete(0)
user_entry.insert(0, "")

pass_entry.delete(0)
pass_entry.insert(0, "")

Answer Source

Your check needs to be:

if stored_user == "admin" or stored_user == "ADMIN":

More info here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download