I have an SQL database that I access using Python and pgdb. I plan on opening access to a group of users, so I would like to incorporate a login function that takes in a username and password that is checked against the database's information on the user. I don't use Python that much, so this has taken me a considerable amount of time with little results. I've found helpful threads on this using PHP but not in Python unfortunately, so I decided to start this thread.
Below is my code. Basically, I would like a login function that returns true if the user exist with a given password. The code below is unresponsive.
Am I setting up the .execute incorrectly with the parameter references? Or is the if statement wrong?
def Login(username,password):
cursor.execute('select %s from db') % username
dbuser = cursor.fetchone()
if dbuser == username:
cursor.execute('select %s from db') % password
dbpass = cursor.fetchone()
if dbpass == password:
return "True"
else:
return "Password is incorrect."
else:
return "Username is incorrect."
Any help is greatly appreciated! Sorry for the newb question...