0

I hashed a password through PHP and posted it to a DB. I want to check it in Python but I get TypeError: expected string or bytes-like object

To my understanding I'm supposed to specify that it's a 2b hash, but can't seem to figure out how to do that with a variable.

import mysql.connector
import bcrypt
mydb = mysql.connector.connect(
    host = "localhost",
    user = "root",
    password = "",
    port = "3307",
    database = "registration"
)



cursor = mydb.cursor()

#username = input("Enter your username: ")
#password = input("Enter your password: ")


cursor.execute("select password from users where username = 'test'")

result = cursor.fetchall()
print (result)

password = "test"

bcrypt.checkpw(password.encode('utf8'),result)

  • In which type did you store it ? Look in fetched results to see if it’s string or bytes – Devyl Jul 17 '22 at 02:10
  • `cursor.fetchall` will return a _list of tuples_, so you must extract the password before passing it to `checkpw`. The answers to the linked duplicate show a number of ways that you might do this. – snakecharmerb Jul 17 '22 at 05:22

0 Answers0