Last active
April 27, 2017 19:03
-
-
Save erickhaendel/83bbb50be042e38ab2dd1f4d89868f9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This fails because the types of bcrypt hashes being generated from php and node are different. Laravel generates the $2y$ while node generates the $2a$. But the good news is the only difference between 2a and 2y are their prefixes. | |
So what you can do is make one of the prefix similar to the other. Like: | |
$phpGeneratedHash = '$2y$10$jOTwkwLVn6OeA/843CyIHu67ib4RixMa/N/pTJVhOjTddvrG8ge5.'; | |
$nodeGeneratedHash = '$2a$10$ZiBH5JtTDtXqDajO6f4EbeBIXGwtcGg2MGwr90xTH9ki34SV6rZhO'; | |
To something like: | |
$phpGeneratedHash = '$2y$10$jOTwkwLVn6OeA/843CyIHu67ib4RixMa/N/pTJVhOjTddvrG8ge5.'; | |
$nodeGeneratedHash = '$2y$10$ZiBH5JtTDtXqDajO6f4EbeBIXGwtcGg2MGwr90xTH9ki34SV6rZhO'; | |
Notice that I replaced the $2a$ of the node hash to $2y$. You can simply do this with: | |
PHP | |
$finalNodeGeneratedHash = str_replace("$2a$", "$2y$", $nodeGeneratedHash); | |
Node | |
finalNodeGeneratedHash = nodeGeneratedHash.replace('$2a$', '$2y$'); | |
Then compare phpGeneratedHash to finalNodeGeneratedHash. | |
Note: It is recommended that if you're comparing in PHP, change the prefix of the NodeJS generated hash to $2y$ and if you're comparing in NodeJS; change the prefix of the PHP generated hash to $2a$. | |
by : http://stackoverflow.com/questions/26643587/comparing-bcrypt-hash-between-php-and-nodejs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment