0

Currently my database stores the 'password' as text, but this says it does not work as shown below (The password is also converted into MD5 hash):

Password 'function':

user_in = input("Please enter a password next to this text: \n")
Password = hashlib.md5()
Password.update(user_in.encode("utf-8"))

Error message:

sqlite3.InterfaceError: Error binding parameter 1 - probably unsupported type.

What I want to know is how I store the hash in a database in SQLITE3

Edit:

cursor=db.cursor()   
sql="insert into Accounts (Username, Password) values(?,?)"
cursor.execute(sql, (Username, Password))                      
db.commit()  

Edit 2:

user_in = input("Please enter a password next to this text: \n")
Password = hashlib.md5()
Password.update(user_in.encode("utf-8"))
Password.hexdigest()
10
  • Are you getting the error when running the python function, or when actually submitting it to the SQLServer? Commented Jun 3, 2017 at 17:21
  • @Polymer Hi again. I am getting the error after I have input the username and password, so when it's being submitted to the SQL server Commented Jun 3, 2017 at 17:22
  • Can you add the code you're using to submit it to the server, please? Also on your server, what type do you have your password set as? Commented Jun 3, 2017 at 17:24
  • @Polymer It is set as text. I will add the code above. Commented Jun 3, 2017 at 17:24
  • Are you using password.hexdigest() for the Password variable? Commented Jun 3, 2017 at 17:27

1 Answer 1

1

Make sure arguments for cursor.execute functions are actually strings and you'll be golden! :)

cursor.execute(sql, (str(Username), str(Password)))

This is done by casting them during the argument pass

Sign up to request clarification or add additional context in comments.

7 Comments

Hey Polymer, I know this kinda unrelated but I wanted to ask a question. If I wanted to add a sign in function, how would I check that the username and password were related?
I am aware I would have to change the user's guess to MD5 as well to correspond to the one in the database but how would I look to make sure that it is that user's password specifically.
And how would I see if Username was in the database then see if the password is correct
Eg. If username IN Accounts.db (Obviously not correct syntax)
Basically, you need to use the username provided, go to your database and get the hashed password. Then, you hash the password they entered with the same md5 and compare it to the one in the database. If both hashings are the same, let them in. If not, they've entered the password in wrong. If you're still confused about this, check out this video by computerphile, great video, and channel youtube.com/watch?v=8ZtInClXe1Q Just to be clear, an MD5 hash is 'unique'. It can be only produced by one set of bytes, hence why it can be used in this circumstance
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.