創建一個密碼散列。
php5.5提供的Password Hashing API。
基本介紹
- 中文名:password_hash
- 外文名:password_hash
- 描述:創建一個密碼散列
簡介,參數,返回值,範例,
簡介
password_hash()函式,用於創建一個密碼散列
(PHP 5>= 5.5.0)
password_hash — Creates a password hash
在PHP5.5之前,我們對於密碼的加密可能更多的是採用md5或sha1之類的加密方式(現在還有存放明文的嗎?),如:echo md5("123456"); //輸出: e10adc3949ba59abbe56e057f20f883e
但是簡單的md5加密很容易通過字典的方式進行破解,隨便找個md5解密的網站就能獲取原始密碼。
參數
password
用戶的密碼。
CautionUsing the PASSWORD_BCRYPT for the algo parameter, will result in the password parameter being truncated to a maximum length of 72 characters.
algo
一個用來在散列密碼時指示算法的密碼算法常量。
options
一個包含有選項的關聯數組。目前支持兩個選項:salt,在散列密碼時加的鹽(干擾字元串),以及cost,用來指明算法遞歸的層數。這兩個值的例子可在 crypt() 頁面找到。
If omitted, a random salt will be created and the default cost will be used.
返回值
Returns the hashed password, 或者在失敗時返回 FALSE.
The used algorithm, cost and salt are returned as part of the hash. Therefore, all information that's needed to verify the hash is included in it. This allows the password_verify() function to verify the hash without needing separate storage for the salt or algorithm information.
範例
Example #1password_hash()example
<?php
/**
* We just want to hash our password using the current DEFAULT algorithm.
* This is presently BCRYPT, and will produce a 60 character result.
*
* Beware that DEFAULT may change over time, so you would want to prepare
* By allowing your storage to expand past 60 characters (255 would be good)
*/
echo password_hash("rasmuslerdorf", PASSWORD_DEFAULT)."\n";
?>
以上例程的輸出類似於:
$2y$10$.vGA1O9wmRjrwAVXD98HNOgsNpDczlqm3Jq7KnEd1rVAGv3Fykk1a