微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

“TypeError: Unicode-objects must be encoding before hashing”即使密码是用 bcrypt 编码的

如何解决“TypeError: Unicode-objects must be encoding before hashing”即使密码是用 bcrypt 编码的

将 bcrypt 用于发布请求时,我不断收到以下错误

TypeError: Unicode 对象必须在散列之前编码

即使我用 utf-8 编码了密码,如以下代码所示:

hashed_pw = bcrypt.hashpw(password.encode('utf-8'),bcrypt.gensalt())

这是更多信息的回溯:

enter image description here

非常感谢任何帮助:)

编辑:

代码失败的函数

def verifyPw(username,password):
    if(not UserExists(username)):
        return False

    hashed_pw = users.find({
        'Username':username
    })[0]['password']

    if(bcrypt.hashpw(password.encode('utf-8'),hashed_pw)==hashed_pw):
        return True
    else:
        return False

请求

enter image description here

解决方法

在评论中解决。

没有将哈希值存储在数据库中,而是将密码存储在字符串中,这就是它给出错误的原因。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。