码迷,mamicode.com
首页 > 其他好文 > 详细

Helpers\Password

时间:2016-07-05 13:53:54      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

Helpers\Password

The password class uses php 5 password_ functions.

To create a hash of a password, call the make method and provide the password to be hashed, once done save the $hash.

$hash = Password::make($password);

When logging in a user their hash must be retrieved from the database and compared against the provided password to make sure they match, for this a method called password_verify is used, it has 2 parameters the first is the user provided password the second is the hash from the database.

    if (Password::verify($_POST[‘password‘], $data[0]->password)) {
     //passed
    } else {
     //failed
    }

From time to time you may update your hashing parameters (algorithm, cost, etc). So a function to determine if rehashing is necessary is available:

if (Password::verify($password, $hash)) {     
   if (Password::needsRehash($hash, $algorithm, $options)) {         
    $hash = Password::make($password, $algorithm, $options); /* Store new hash in db */     
   } 
}

Helpers\Password

标签:

原文地址:http://www.cnblogs.com/chunguang/p/5643189.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!