I'm writing a python script that allows for sign up and log in, the signup works fine, but the login and authentication doesn't work even if the user is registered.
def userlogin(self, ID, password):
try:
statement = conn.execute('SELECT ID FROM USERS')
conn.commit()
for row in statement:
if ID in statement:
print "%d" % ID
pas = conn.execute('SELECT PASSWORD FROM USERS WHERE ID = %d' % (ID))
conn.commit()
if password in pas:
print "welcome user %d" % ID
conn.close()
else:
print "username/password incorrect!"
conn.close()
else:
print "Incorrect ID! If you are not a user, please register here."
except IOError:
print "Select statement could not execute!"
I know this is not the best way to write this function, I'm doing it for practice. Even if the password and ID are entered correctly, it always prints Incorrect ID. Is there anything wrong with the if statement?
pas = conn.execute("SELECT password FROM users WHERE ID = ?", (ID,))