dqluw20882 2016-02-02 06:04
浏览 82
已采纳

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

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

Node JS Code:

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

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

Is it possible to generate the ouput hash using input simha in PHP

I am trying the below one, but it is generating different hash

password_hash($password, PASSWORD_BCRYPT) 
//output : $2y$10$CfihL9RipXW88JAVvlyFlegM5BAyD5xQmNutjm9KepeXUn5cAwIX2
  • 写回答

1条回答 默认 最新

  • dsgni26260 2016-02-02 06:20
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大