如何解密一个 "sha512" 加密的变量?

How to decrypt a "sha512" encrypted variable?

我有这个代码:

$password = vancab123;

password_hash(base64_encode( hash('sha512',$password, true) ), PASSWORD_DEFAULT );

数据库存储值:

$password = y$jUa8ZEFBX5lfsBmySUnJFeSSyKwQ1v/emazJZPh8MwJ0g0lLbmjYC;

我的问题:

我在 "remember me" 函数中使用了它。如果用户使用该功能 his/her 凭据(电子邮件和密码)将使用 cookie 保存 7 天。

我的问题是因为邮箱和密码会自动填满邮箱和密码文本框,密码文本框字符太长因为它被散列了。

如何将散列密码的长度与 original/unhashed 密码相匹配?

而且您无需跳过所有这些步骤即可使用 password_hash,这就是检查输入的密码是否与之前的散列密码匹配的方法

The point of a HASH is it cannot (within a sensable time frame) be converted back to its original value. Instead you have to compare it using password_verify() to the unhashed value the user enters when they return and attempt to login using the same password.

$password = 'vancab123';

$hashed_pwd = password_hash($password);

// test the hashed password

if ( password_verify($password, $hashed_pwd) ) {
    //password entered is OK
} else {
    //password entered is WRONG
}

在您澄清问题后添加:

Read this for a Remember me functionality What is the best way to implement "remember me" for a website?

散列是任意值的单向转换。它们本质上是不可逆的。在您的情况下,您必须散列用户提供的密码,从数据库中检索值,然后比较两个散列值。

唯一的选择是彩虹攻击背后的范例,在这种范例中,您散列所有可能的可能性并将它们存储为键值对,但这是大量数据。