php crypt mysql password_使用PHP 5.5的password_hash和password_verify函数
使用PHP 5.5的password_hash和password_verify函數
假設我想為用戶存儲密碼,這是使用PHP 5.5的password_hash()功能(或者這個版本的PHP 5.3.7+:https://github.com/ircmaxell/password_compat)的正確方法嗎?$options?=?array("cost"?=>?10,?"salt"?=>?uniqid());$hash?=?password_hash($password,?PASSWORD_BCRYPT,?$options);
然后我會這樣做:mysql_query("INSERT?INTO?users(username,password,?salt)?VALUES($username,?$hash,?"?.?$options['salt']);
要插入數據庫。
然后驗證:$row?=?mysql_fetch_assoc(mysql_query("SELECT?salt?FROM?users?WHERE?id=$userid"));$salt?=?$row["salt"];$hash?=?password_hash($password,?PASSWORD_BCRYPT,?array("cost"?=>?10,?"salt"?=>?$salt));if?(password_verify($password,?$hash)?{
//?Verified}
總結
以上是生活随笔為你收集整理的php crypt mysql password_使用PHP 5.5的password_hash和password_verify函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《楚乔传》左宝仓真实身份揭秘 与寒山盟有
- 下一篇: python 局域网 主机名_使用pyt