I cannot get this login program to take the username and password fetched from database and compare it to entered one. It just says that the username is incorrect when it is not. Please help thanks
def loginpage():
bottom= Toplevel()
bottom.title("SmartCards - Login")
bottom.iconbitmap(r"C:\Users\Ethan\Documents\Comp NEA\Icon.ico")
bottom.config(padx=50, pady=50, bg=BACKGROUND_COLOR)
def submit2():
user1 = username1.get()
passwrd1 = password1.get()
sql = 'SELECT * FROM login WHERE "user1" == username'
sql2 = "SELECT * FROM login WHERE 'passwrd1' == password"
c.execute(sql)
c.execute(sql2)
conn.commit()
if sql==user1:
if sql2==passwrd1:
messagebox.showinfo("Success","Login Successful!")
else:
messagebox.showwarning("Error","Password Incorrect!")
else:
messagebox.showwarning("Error","Username Incorrect!")
userbox = Label (bottom, text="Username:")
userbox.grid(row=0, column=0)
username1 = Entry(bottom)
username1.insert(0,"")
username1.grid(row=1, column=0)
passbox1 = Label (bottom, text="Password:")
passbox1.grid(row=2, column=0)
password1 = Entry(bottom)
password1.insert(0,"")
password1.grid(row=3, column=0)
submit = Button(bottom, text="Submit", command=submit2)
submit.grid(row=4, column=0)
Use a single query for both username and password, with placeholder tokens instead of literal values:
Then execute the query, providing actual values for the placeholders:
Then fetch the results of the query and look at how many matching rows were found: