Jump to content

bcrypt passwords in a database


skippt

Recommended Posts

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?

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.