I am trying to verify that the correct password has been entered into the password input box on my site. The aim is to return true if the password entered matches the password in the SQLite table that corresponds the "usernick" entered in the username input box.
def check_login(db, usernick, password):
"""returns True if password matches stored"""
cursor = db.cursor()
cursor.execute("SELECT password FROM users WHERE nick='%s'" % usernick)
passcheck = cursor.fetchone()
print(usernick)
print(password)
print(passcheck)
if password == passcheck:
return True
else:
return False
I used the print's to see where my code was going wrong. The correct username and passwords are being inputted into the function, but print(passcheck) is outputting: ['48181acd22b3edaebc8a447868a7df7ce629920a']
I now realise that this is because the password is decrypted. How do i decrypt the password?
You don't. You encrypt the password the user has entered and check that it matches the encrypted version in the database.
However without any details of how the database certain was originally created, there is no way to help you further.
Edit
Remember that fetchone() always returns a tuple, even if you only selected a single column. Do passcheck = cursor.fetchone()[0].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With