Can you help me to fix this problem:
TypeError: can't concat bytes to str
I am trying to safely store hash + salt passwords.
I think the problem is that my salt is a byte object.
How can I transform it into a string?
Or is there a way to hash it better?
import base64
import hashlib
import os
def getDigest(password, salt=None):
if not salt:
salt = base64.b64encode(os.urandom(32))
digest = hashlib.sha256(salt + password).hexdigest()
return salt, digest
def isPassword(password, salt, digest):
return getDigest(password, salt)[1] == digest
print(getDigest('batman'))
You can do
salt = salt.decode("utf-8")
aftersalt
is encoded to convert it to string.