首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Argon2验证始终返回True

Argon2验证始终返回True
EN

Stack Overflow用户
提问于 2019-06-09 08:22:36
回答 1查看 895关注 0票数 0

我正在使用argon2和nodejs,并且我正在尝试验证密码:

代码语言:javascript
复制
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.ify()总是返回true,但我不确定为什么。

EN

回答 1

Stack Overflow用户

发布于 2020-05-05 23:44:04

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56511085

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档