如何解密php中的哈希密码?用password_hash()方法散列的密码 [英] How to decrypt the hashed password in php ? password hashed with password_hash() method

查看:241
本文介绍了如何解密php中的哈希密码?用password_hash()方法散列的密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想解密通过php的password_hash()方法加密的加密密码.

I want to decrypt the encrypted password that is encrypted by php's password_hash() method.

<?php

    $password = 12345;
    $hashed_password = password_hash($password, PASSWORD_DEFAULT);

?>

在上面的代码中,我想将 $ hashed_pa​​ssword 解密为 12345 .我该怎么办.

in above code i want to decrypt $hashed_password to 12345. how can i do it.

推荐答案

您不需要

所使用的算法,成本和费用作为哈希的一部分返回.因此,验证散列所需的所有信息是包含在其中.这允许password_verify()函数进行验证散列,不需要为salt或算法单独存储信息.

The used algorithm, cost and salt are returned as part of the hash. Therefore, all information that's needed to verify the hash is included in it. This allows the password_verify() function to verify the hash without needing separate storage for the salt or algorithm information.

    $passwordEnteredFirstTime = '12345';
    $passwordEnteredSecondTime = '12345';

    $passwordHash = password_hash($passwordEnteredFirstTime, PASSWORD_BCRYPT);
    $passIsValid = password_verify($passwordEnteredSecondTime, $passwordHash);
    echo $passIsValid ? 'correct password' : 'wrong password';

这篇关于如何解密php中的哈希密码?用password_hash()方法散列的密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆