Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 散列错误+;Salt密码_Python_Authentication_Python 3.x_Hash_Salt - Fatal编程技术网

Python 散列错误+;Salt密码

Python 散列错误+;Salt密码,python,authentication,python-3.x,hash,salt,Python,Authentication,Python 3.x,Hash,Salt,你能帮我解决这个问题吗 TypeError: can't concat bytes to str 我正在尝试安全地存储哈希+salt密码。 我认为问题在于我的salt是一个字节对象 如何将其转换为字符串? 还是有更好的解决方法 import base64 import hashlib import os def getDigest(password, salt=None): if not salt: salt = base64.b64encode(os.urandom

你能帮我解决这个问题吗

TypeError: can't concat bytes to str
我正在尝试安全地存储哈希+salt密码。
我认为问题在于我的salt是一个字节对象

如何将其转换为字符串?
还是有更好的解决方法

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'))

您可以执行
salt=salt。在
salt
编码后解码(“utf-8”)
,将其转换为字符串