2013-03-18 118 views
0

我正在寫一段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腳本只是給了我一個白色的屏幕。 有人可以幫助我:)?

乾杯

回答

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); 
+0

是的,但網站運行在服務器上,所以我不能改變任何東西到PHP​​版本,但我會嘗試使用外部文件。謝謝 ! – tortilla 2013-03-20 12:22:35

+0

@ user2156757 - 兼容包可能是早期PHP版本的最佳解決方案。 – martinstoeckli 2013-03-20 12:34:19

+0

這些只是外部庫我可以放在htmldocs中嗎?我可能會尋找其中一個:) – tortilla 2013-03-21 10:47:59