title: Verify password hash in nodejs which was generated in php
body: <p>My php code generates a hash using <code>password_hash</code> which I store in a database. Below is the PHP code:</p>
  
  <pre><code>$hash = password_hash($value, PASSWORD_BCRYPT, array('cost' =&gt; $cost));
  </code></pre>
  
  <p>I would like to verify / check the password against this hash in nodejs.</p>
  
  <p>I saw lot of node modules (bcrypt, phpass, node-bcrypt), but all of them give me false. Below is sample hash generated in php and which I m trying to verify in nodejs.</p>
  
  <pre><code>var hash = '$2y$08$9TTThrthZhTOcoHELRjuN.3mJd2iKYIeNlV/CYJUWWRnDfRRw6fD2';
  
  var bcrypt = require('bcrypt');
  
  bcrypt.compare("secret", hash, function(err, res) {
      console.log(res);
  });
  </code></pre>
  
  <p>(Here secret is real password)</p>
  
  <p>My current workaround is to call a php script via node to verify (for anybody who needs a workaround)</p>
  
  <pre><code>var exec = require('child_process').exec;
  var cmd = 'php verify.php password encryped_pasword';
  exec(cmd, function (error, stdout, stderr) {
    // output is in stdout
    console.log(stdout);
   //If stdout has 1 it satisfies else false
  });
  </code></pre>
  
  <p>This is a hack and not a good answer to this problem. Is there a way to verify the password in nodejs without using a workaround like this?</p>