我可以用 werkzeug.security 的 check_password_hash 解密 Bcrypt 散列密码吗

Can I decrypt a Bcrypt hashed password with werkzeug.security's check_password_hash

是否可以使用以下方法解密以前散列的密码:

Bcrypt - b$

使用时:

from werkzeug.security import generate_password_hash, check_password_hash

我假设如果我可以指定 werkzeug.security 应该使用哪种散列算法来检查密码,那么即使它们是不同的工具,它也会起作用。

也许我太天真了。

我像这样加密了密码:

application = Flask(__name__)
bc = Bcrypt(application)
password=bc.generate_password_hash(data['password_input'])

但是想这样解密:

application = Flask(__name__)
from werkzeug.security import generate_password_hash, check_password_hash
if check_password_hash(user.password, password):
    pass

样本(虚拟)散列:

bWSJfIg.YkR/Bn469IX4OlOCJx.HMWKxR8NysSynGa8QHf/4rawq

我会使用 Bcrypt 库,但由于 ,我无法让它与 Elastic Beanstalk 一起工作。

不,你不能这样做。这就是使用 Bcrypt to encrypt the password in the first place. If you were able to recover a password from a hash, then any breach of your database would result in users' credentials being accessible and a hash would be no better than storing a password in clear text. See more about password hashing here.

的全部意义所在

您所能做的就是接受一个新的密码尝试,对其进行哈希处理,并将该哈希值与您已知的哈希值进行比较。 check_password_hash 无法处理 Bcrypt 哈希,因此您需要使用 bcrypt.hashpw 来处理

import bcrypt
isSamePassword = bcrypt.hashpw(new_password, stored_hash)