Why does not the string equal to a text value in sqlite3 database (Python) Why does not the string equal to a text value in sqlite3 database (Python) tkinter tkinter

Why does not the string equal to a text value in sqlite3 database (Python)


thePass is an iterable that yeilds tuples, key is a string.

In general, the python db api always returns database rows as tuples because you can select multiple things in a statement. Rather than having confusing logic that needs to look at the query to determine the return type of the row (for both the database api and the caller), the spec says to just return a tuple always.

You need to compare key with the row correctly...

rows = c.execute("Select pass FROM user_pass")for row in rows:    if row[0] == thePass:        print("right password")        returnelse:    print("Wrong Password")    

Note, this probably isn't what you actually want. All it does is verify that one row in the user_pass table has that pass value. More likely, you want to filter the query against the username and then check the password:

c.execute("SELECT pass FROM user_pass WHERE username = ?", username)result = c.fetchone()  # username should be unique I assume :-)if result[0] == salt_and_hash(key):    print("Yeah!")else:    print("No!")


c.execute("SELECT pass FROM user_pass") is returning a tuple, not a string, but key is a string. You need to get the first value from the tuple and compare that to your key argument, so change your function to this:

def check_password(key):    thePass= c.execute("SELECT pass FROM user_pass")[0] # Changed here    if key == thePass:        print("right Password")    else:        print("Wrong Password")