Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

bcrypt passwords in a database

$
0
0

Hi,

 

I'm currently using this tutorial to guide me and I'm trying out some of the examples but I don't really understand it.

 

The version of PHP I'm using is 5.3.27 so I'm using this compatibility library.

 

Okay, so my code for registering a user is below:

$options = array('cost' => 11);
$password = password_hash($password, PASSWORD_BCRYPT, $options);

It takes the password inserted into a form, then I take the outputted $password and enter it into the database.

 

For the password verify bit, I have:

$hash = '$2y$11$6SXlwd2iKZcYuz9guncYXe39/x6lUR5u4EfJQr.qKhEPAuXFgLWeS';

if (password_verify($password, $hash)) {
    echo 'Password is valid!';
} else {
    echo 'Invalid password.';
}

That works fine, except I need to grab the hash from the database. When I try to match that to the password entered into a form to the hash from the database, it comes up with invalid password.

 

I think I'm doing this completely wrong.

 

Can anyone help me out please?

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles