如何解密我用 Bcrypt 散列的密码(用于显示目的)?

How to de-crypt password that i've hashed with Bcrypt (for display purposes)?

我正在创建一个允许用户使用 username/password 组合登录的应用程序。 我有一个创建这些用户的管理员帐户,并且在将密码存储在 mySQL 数据库中时对密码进行哈希处理。 但是,如果用户忘记了 his/her 密码,我希望能够在此管理员帐户中看到它处于未散列状态并能够更改它。 这可能吗?如何解决?

我使用的技术是Laravel/Vue/mySQL/Bcrypt。

你不能。

散列是一种 one-way 数学运算,不能 un-done。您只能创建一个新的散列并比较两者。

bcrypt 是哈希算法,而不是加密算法。这意味着它是不可逆的。

Bcrypt like any other salted hash method use the salt to avoid that the same password hashes to the same string. It is doing that by initially generating the salt randomly and then hashing password and salt. This can only be verified if the same salt is used when verifying. This is why the salt is saved together with the hash.

Bcrypt like any other iterated hash method can not directly be inverted, but you can try all possible passwords to see if they hash to the same result. In case of salted methods you cannot precompute this, because you have to try with the actual salt (as described above).

如果你想拥有可以是 de-encrypted 的密码,你可能需要考虑一种加密算法而不是散列算法,或者你可以看看 Laravel 自己的方法encrypt(),尽管这需要您重写应用程序的身份验证方法,并且可能被认为不太安全。

更多信息:https://laravel.com/docs/5.8/encryption