Hashing error + salt password
Help me solve this problem:
TypeError: can't concat bytes to str
I am trying to store hash + salt passwords securely.
I think the problem is that my salt is a byte object.
How do I convert it to a string? Or is there a better way to hash it?
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'))
+3
source to share