hash_pbkdf2不给出输出
问题描述:
我正在写一段php代码,但是并没有给出我想要的输出;hash_pbkdf2不给出输出
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或盐它的工作原理哈希之前,但它确实没有什么之后,整个PHP脚本只是给了我一个白色的屏幕。 有人可以帮助我:)?
干杯
答
功能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);
是的,但网站运行在服务器上,所以我不能改变任何东西到PHP版本,但我会尝试使用外部文件。谢谢 ! – tortilla 2013-03-20 12:22:35
@ user2156757 - 兼容包可能是早期PHP版本的最佳解决方案。 – martinstoeckli 2013-03-20 12:34:19
这些只是外部库我可以放在htmldocs中吗?我可能会寻找其中一个:) – tortilla 2013-03-21 10:47:59