【问题标题】:Error Hashing + Salt password错误哈希 + Salt 密码
【发布时间】:2015-09-02 23:33:33
【问题描述】:

你能帮我解决这个问题吗:

TypeError: can't concat bytes to str

我正在尝试安全地存储 hash + 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'))

【问题讨论】:

    标签: python authentication python-3.x hash salt


    【解决方案1】:

    你可以在salt被编码后将salt = salt.decode("utf-8")转换成字符串。

    【讨论】:

      猜你喜欢
      • 2017-09-10
      • 2012-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-07
      • 1970-01-01
      • 2016-11-22
      • 2011-09-10
      相关资源
      最近更新 更多