Created
May 29, 2019 13:44
-
-
Save Just1B/c71cfb62c91424bae22ddf198b8d9e71 to your computer and use it in GitHub Desktop.
Compare a PHP bcrypt hash with Node.js ( From angristan.xyz )
This file contains hidden or 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
| const bcrypt = require('bcryptjs'); | |
| const exec = require('child_process').exec | |
| const password = 'test'; | |
| const cmd = '/usr/local/bin/php ./password.php' | |
| exec(cmd, (err, stdout, stderr) => { | |
| // See https://en.wikipedia.org/wiki/Bcrypt#Versioning_history | |
| const hash = stdout.replace('$2y$', '$2a$'); | |
| bcrypt.compare(password, hash).then(function(res) { | |
| // Should output true | |
| console.log(res); | |
| }); | |
| }); |
This file contains hidden or 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
| <?php | |
| $password = "test"; | |
| $hash = password_hash($password, PASSWORD_BCRYPT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment