0

大家好,我正在使用 speakeasy npm 模块在一个时间范围内生成 totp 现在下面是我的工作流程,任何人都可以告诉我我是否遗漏了什么。当用户注册时,我在请求中获取其手机号码,然后将其用作秘密,我正在生成我的 totp,以便每个用户的 totp 可以是唯一的

var mobile_no = req.body.mobile_no;
speakeasy.totp({key: mobile_no, step: 60})

我通过我的用户的手机号码发送,然后将其发送到服务器以便现在在服务器上检查我正在从 totp 模块再次检查

var mobile_no = req.body.mobile_no;
var sent_totp = req.body.totp;
if (sent_totp == speakeasy.totp({key: mobile_no, step: 60})) {
console.log('Registration successfull');
} else {
console.log('OTP does not match');
}

如果匹配,那么我进行注册,否则现在不是我做的一切是否正确?请告诉我,我的方法有问题吗

4

1 回答 1

1

 var code = speakeasy.totp({key: 'abc123'});
    users.get(data.phone_number, function (geterr, doc,         key) {
      if (geterr) {
        createUser(data.phone_number, code, socket);
      }
      else if (checkVerified(socket, doc.verified, data.phone_number) == false) {
        socket.emit('update', {message: "Your message goes in here"});
        socket.emit('code_generated'); //if code have been generated
      }
    });

//希望这可以帮助

于 2018-11-21T23:38:14.477 回答