hash_pbkdf2没有输出

时间:2013-03-18 22:30:07

标签: php hash passwords pbkdf2

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

干杯

1 个答案:

答案 0 :(得分:0)

函数hash_pbkdf2()将在PHP 5.5版中引入,所以我怀疑你安装的PHP版本还不支持这个功能。在调用函数之前,先测试BCrypt是否已定义,但函数hash_pbkdf2()(基于密码的键 - 派生函数)与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);
相关问题