简体   繁体   English

比较Nodejs在PHP中生成的bcrypt哈希

[英]Compare Nodejs generated bcrypt hash in PHP

Just to know about bcrypt hash comparison in different platforms, that I have one brypt hash which is generated at Nodejs server, now I am moving to PHP, I want to know about is this possible to compare already created bcrypt hashes(generated in Nodejs) in PHP 只是想了解不同平台上的bcrypt哈希比较,我有一个在Node.js服务器上生成的Brypt哈希,现在我正在使用PHP,我想知道是否有可能比较已经创建的bcrypt哈希(在Node.js中生成)在PHP中

Node JS Code: 节点JS代码:

function hash(password) {
  return new Promise(function(fulfill, reject) {
    bcrypt.hash(password, 8, function(err, hashedPassword) {
      if (err) {
        reject(err);
      } else {
        fulfill(hashedPassword);
      }
    });
  });
}

Input : simha 输入: simha

output: $2a$10$c/EwGsRkoV4XHmsOJYWZ6.LurbDUFW.eq83SI8eu5JaMOsr6PyLrm 输出: $2a$10$c/EwGsRkoV4XHmsOJYWZ6.LurbDUFW.eq83SI8eu5JaMOsr6PyLrm

Is it possible to generate the ouput hash using input simha in PHP 是否可以使用PHP中的输入simha生成输出哈希

I am trying the below one, but it is generating different hash 我正在尝试下面的方法,但是它会生成不同的哈希值

password_hash($password, PASSWORD_BCRYPT) 
//output : $2y$10$CfihL9RipXW88JAVvlyFlegM5BAyD5xQmNutjm9KepeXUn5cAwIX2

You shouldn't expect them to match, at least by default. 至少在默认情况下,您不应期望它们匹配。 This is because for both functions, a random salt is chosen every time you hash a value. 这是因为对于这两个函数,每次哈希值时都会选择随机盐。

The important thing is not that the hash outputs match, but that they still validate. 重要的不是哈希输出是否匹配,而是它们仍然有效。 So you could take the hashed output from node.js and use it with password_verify() in PHP for example, and it should validate. 因此,您可以从node.js中获取散列的输出,并将其与PHP中的password_verify()使用,并且它应该进行验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM