当前代码:
import bcrypt
passwd = b'False'
salt = bcrypt.gensalt()
hashed = bcrypt.hashpw(passwd, salt)
x = input()
print(hashed == bcrypt.hashpw(x, hashed))
如何在b''
的撇号之间插入一个值?
这是我尝试过的:
x = b'%s' % (input())
CMD上的输出
x = b'%s' % (input())
TypeError: %b requires a bytes-like object, or an object that implements __bytes__, not 'str'
目标
我正在尝试将输入与哈希密码进行比较。
[使用前应了解b''
的作用,这将使您能够找到正确方向的解决方案。
答案是:它表明您分配的是字符串字节文字。这基本上意味着您有一堆字节作为数据。 (请参见these answers)
一旦您知道您可以搜索如何在Python中将字符串转换为字节,这将导致您here
因此,您最初的问题的答案(是的,您应该使用checkpw
)是:
print(hashed == bcrypt.hashpw(x.encode('utf-8'), hashed))