password_hash


password_hash

文章插图
password_hash【password_hash】创建一个密码散列 。
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";?>