Argon2验证始终返回True

时间:2019-06-09 00:22:35

标签: node.js

我正在将argon2与nodejs一起使用,并且正在尝试验证密码:

global.user = [{username:"u1", password:"hidden"}];
  // run the password in the argon2 hashing alg
  const signup = async function(password) {
    // hash password using argon2i (mainly for passwords)
    var key = await argon2.hash(password, {
      type: argon2.argon2i,
      timeCost: 200,
      hashLength: 128,
    });
    return key;
  }

  var k = signup(req.body.password);
  k.then(function(result) {
    console.log(result);
    global.user.push({username:req.body.username, password:result})
    res.json(global.user);
  })

  var success = false;
  if(argon2.verify(item.password, "meow")) {
    console.log(req.body.password);
    console.log(item.password);
    success = true;
  }

argon2.verify()总是返回true,无论我将哈希与什么进行比较,但我不确定为什么。

1 个答案:

答案 0 :(得分:0)

这是因为argon2.verify返回了一个promise,当将其隐式转换为布尔值时,它为true。请改用await argon2.verify