网络科技

    今日:350| 主题:246377
收藏本版
互联网、科技极客的综合动态。

[其他] How to Hashing Password in PHP 5.5 with Password Hashing API

[复制链接]
yuy527 发表于 2016-10-5 15:40:53
175 12

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
Thistutorial show you how to hashing passwords inPHP 5.5 with hashingAPI. There is a large number of web developers using old and less secure algorithm like MD5 and SHA1 encryption etc but those passwords are plain strings. In this new hashing API it uses bcrypt (its a  key derivation function for passwords). In this article we are going to explore PHP’s new hashing API.
   
How to Hashing Password in PHP 5.5 with Password Hashing API-1 (generated,function,password,default,article)

   DOWNLOAD CODE DEMO
   password_hash() – used to hash the password.
   password_verify() – used to verify a password against its hash.
  password_hash()

  [code] $password = "phpgang";
$hash = password_hash($passwod, PASSWORD_DEFAULT);
?>
[/code]  Hash generated from above code is:
  [code]$2y$10$vdd/HDckxSzFdOMLZ4Rhh.M3MQeOsPCwcsvAFW3MJWMKdxdv63.
[/code]  In this function the first parameter is your password and second parameter used to specify the algorithm to hash password.
   PASSWORD_DEFAULT – is the bcrypt algorithm (default as of PHP 5.5.0).
  If you are using PASSWORD_DEFAULT in your projects, its recommended to create column size must be larger than 60 characters to save hash if you define column to 255 would be good.
   Most important is that you don’t have to provide salt (appending or pre-appending is called salt ) this API can automatically generate random salt but if you want to give your own salt then there is an options to add it as a third parameter in it.
  [code] $options = [
    'salt' => function_for_salt(), // write your own code to generate a salt
    'cost' => 11 // allows for you to change the CPU cost of the algorithm
];
echo password_hash($password, PASSWORD_DEFAULT, $options);
?>
[/code]   We have generated hashed password with this new API now its time to verify these passwords with password_verify() . This function takes plain password and hashed password which we have saved in database.
  password_verify()

  [code] $passwod = "phpgang";
$hash = "$2y$10$vdd/HDckxSzFdOMLZ4Rhh.M3MQeOsPCwcsvAFW3MJWMKdxdv63.";
if (password_verify($password, $hash))
{
    // Password valid!!
}
else
{
    // Invalid password.
}
?>
[/code]   This way you can verify your passwords and make your websites passwords strong with the latest API. If you are not using PHP 5.5 then there is a library available you can use that library [ here ] and create passwords in latest encryption.
  I hope you like this tutorial feel free to comment your views.
友荐云推荐




上一篇:US Mobile launches private Scrambl3 app for free calls and texts
下一篇:谷歌发布了一款新手机,顺便黑了苹果一大波
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

蒋道兵 发表于 2016-10-5 17:24:45
帮顶,帮顶,快速顶贴中・・・・・・
回复 支持 反对

使用道具 举报

sToΝě 发表于 2016-10-5 17:29:43
不觉名利。。。。。
回复 支持 反对

使用道具 举报

恨山 发表于 2016-10-5 17:42:03
经验之谈,谢谢yuy527了,请继续努力
回复 支持 反对

使用道具 举报

mengtiantang 发表于 2016-10-5 17:59:23
小鲜肉心塞
回复 支持 反对

使用道具 举报

halokr 发表于 2016-10-5 18:17:27
我来一个充满激情的回复
回复 支持 反对

使用道具 举报

zhcsyxgs 发表于 2016-10-12 02:48:51
你踩我的脚没事,可别踩我的鞋呀!
回复 支持 反对

使用道具 举报

蹇韵 发表于 2016-11-8 13:00:56
我死了,但是在烈火中我又站起来了,你猜是涅磐,还是尸变?
回复 支持 反对

使用道具 举报

傲珊 发表于 2016-11-9 20:41:54
看了这么多帖子,第一次看到这么经典的!
回复 支持 反对

使用道具 举报

崔菁 发表于 2016-11-11 18:32:53
看起来好像不错的样子
回复 支持 反对

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表