Skip to content

Instantly share code, notes, and snippets.

@Just1B
Created May 29, 2019 13:44
Show Gist options
  • Select an option

  • Save Just1B/c71cfb62c91424bae22ddf198b8d9e71 to your computer and use it in GitHub Desktop.

Select an option

Save Just1B/c71cfb62c91424bae22ddf198b8d9e71 to your computer and use it in GitHub Desktop.
Compare a PHP bcrypt hash with Node.js ( From angristan.xyz )
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);
});
});
<?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