BCrypt Verify Problem

669 views
Skip to first unread message

matt smith

unread,
Jan 15, 2014, 3:51:30 PM1/15/14
to f3-fra...@googlegroups.com
I'm storing passwords using the bcrypt add-on. It hashes the password, and it gets stored in the DB just fine. Problem is when I try to use the verify function passing in the (cleartextpassword, hashedpassword) it always returns false. I double-checked that all the data getting passed to the function is correct. I've tried both passing in my own salt and having one generated.

Any ideas?

Thanks.

stu warneski

unread,
Jan 15, 2014, 4:55:48 PM1/15/14
to f3-fra...@googlegroups.com
don't you just get the hashed from the db, hash the cleartext verified passed in with the same salt used to store the db hashed version, then compare?

echo the hashed vs the verified hash, perhaps they are not a match?

matt smith

unread,
Jan 15, 2014, 5:01:41 PM1/15/14
to f3-fra...@googlegroups.com
No - they are different values each time you hash, even when using the same salt. The verify method does something different.

bcosca

unread,
Jan 15, 2014, 5:46:50 PM1/15/14
to f3-fra...@googlegroups.com
$bcrypt=\Bcrypt::instance();

// Without a salt
$hash=$bcrypt->hash('hell0_w0rld');
var_dump($hash);
var_dump($bcrypt->verify('hacked_this',$hash));
var_dump($bcrypt->verify('hell0_w0rld',$hash));

// Using a salt that generates a constant hash
$hash=$bcrypt->hash('hell0_w0rld','WelcomeToTheWastelands');
var_dump($hash);
var_dump($bcrypt->verify('hacked_this',$hash));
var_dump($bcrypt->verify('hell0_w0rld',$hash));

Output:

string '$2y$10$JxrnXNwX7VF2kBsD6zDzKOo8yVnGFzQyVCRpmIHPe/JPDYFtJMXmG' (length=60)
boolean false
boolean true

string '$2y$10$WelcomeToTheWastelandeBWxFLqdLbyzz2HsEtHelwDeW/SiiSTK' (length=60)
boolean false
boolean true

ikkez

unread,
Jan 15, 2014, 6:47:47 PM1/15/14
to f3-fra...@googlegroups.com
Also notice that you need minimum PHP version 5.3.7 to make bcrypt work properly.

matt smith

unread,
Jan 15, 2014, 9:26:02 PM1/15/14
to f3-fra...@googlegroups.com
Thanks so much for the replies. Of course in the end it wasn't F3's fault, but how it was getting stored into the database. I didn't realize with Cortex that when you have a set_field function, that it automatically gets called, I just figured that was naming convention. So it was being hashed twice.
Reply all
Reply to author
Forward
0 new messages