2012-09-08 44 views
0

經過半天的閱讀,瞭解密碼的正確編碼方式後,我感到非常沮喪,我選擇了這樣做。不過,我不確定這是否是最好的方法。提前致謝。使用mcrypt_create_iv()和crypt()加密我的密碼

$password= "abc123"; 
$salt = mcrypt_create_iv(32, MCRYPT_RAND); 
$this_will_be_stored_in_db= crypt($password,$salt); 
echo $this_will_be_stored_in_db; 

回答

0

的事情是,隱窩()是單向散列,這是不一樣的東西編碼,所以你將無法得到原始值,你通過通過代碼的值之後。如果哈希是你想用密碼做的,我會推薦使用bcrypt。這裏是你如何實現它的一個例子:

$password = 'secretPassword'; 
$salt = '$2a$13$'.substr(sha1($password),0,22); 
$hashed_value = substr(crypt($pass, $salt), 29); 

你可以閱讀更多關於這個站點bcrypt:http://www.nathandavison.com/posts/view/13/php-bcrypt-hash-a-password-with-a-logical-salt

+0

什麼是$通變量 –