1

我正在编写一段 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 脚本只会给我一个白屏。有人可以帮我:)吗?

干杯

4

1 回答 1

0

该功能hash_pbkdf2()将在 PHP 5.5 版本中引入,所以我怀疑您安装的 PHP 版本尚不支持该功能。在调用该函数之前,您会测试是否定义了 BCrypt,但该函数hash_pbkdf2()(基于密码的密钥派生函数)与 BCrypt 无关。

建议使用 BCrypt 对密码进行哈希处理,但在 PHP 5.5 版中,您可以使用它来password_hash()代替。还存在适用于早期版本的兼容包

// 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);
于 2013-03-19T07:53:44.940 回答