【问题标题】:hash_pbkdf2 gives no outputhash_pbkdf2 没有输出
【发布时间】:2013-03-07 11:03:48
【问题描述】:

我正在编写一段 php 代码,但没有给我想要的输出;

function passhash($unhashPass){

if(CRYPT_BLOWFISH != 1) {
       throw new Exception("bcrypt not supported in this installation.);
    }
$salt = "test123";
$password = hash_pbkdf2 ("sha256", $unhashPass, $salt, 1, 20);
echo $password;
return $password;
} 

当我在哈希之前放置 unhashpass 或 salt 的 echo 语句时,它可以工作,但在它什么都不做之后,整个 php 脚本只会给我一个白屏。 有人可以帮我:)吗?

干杯

【问题讨论】:

    标签: php hash passwords pbkdf2


    【解决方案1】:

    hash_pbkdf2()函数将在PHP 5.5版本中引入,所以我怀疑你安装的PHP版本还不支持这个函数。调用函数前,先测试是否定义了BCrypt,但函数hash_pbkdf2()(password-based-key-derivation-function)与BCrypt无关。

    建议使用 BCrypt 对密码进行哈希处理,在 PHP 5.5 版本中,您可以使用 password_hash() 来代替。早期版本还存在compatibility pack

    // Hash a new password for storing in the database.
    // The function automatically generates a cryptographically safe salt.
    $hashToStoreInDb = password_hash($password, PASSWORD_BCRYPT);
    
    // Check if the hash of the entered login password, matches the stored hash.
    // The salt and the cost factor will be extracted from $existingHashFromDb.
    $isPasswordCorrect = password_verify($password, $existingHashFromDb);
    

    【讨论】:

    • 是的,但是该站点在服务器上运行,因此我无法将任何内容更改为 php 版本,但是我会尝试使用外部文件。谢谢!
    • @user2156757 - 兼容包可能是早期 PHP 版本的最佳解决方案。
    • 那些只是我可以放在 htmldocs 中的外部库,对吗?我可能会寻找其中之一:)
    • @user2156757 - 是的,它只是一个独立的 php 文件,只需将其复制到您的项目中即可。然后你可以像答案中的例子那样调用函数。
    猜你喜欢
    • 2014-06-28
    • 1970-01-01
    • 2014-04-15
    • 1970-01-01
    • 2021-04-10
    • 2015-05-11
    • 2018-03-19
    • 2021-02-08
    • 2021-12-29
    相关资源
    最近更新 更多