aman verma
aman verma

Reputation: 762

Mobile verification in android app using speakeasy as npm module for generating otp?

Hello all i am using speakeasy npm module for generating totp within a time frame now below is my work flow now can anyone please tell me that am i missing something or not. When a user sign up i am getting its mobile number in request, and then using it as a secret and i am generating my totp so that totp can be unique per user

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

which i am sending on my user's mobile number who then sends it to the server for check now at the server i am checking it again from totp module

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');
}

and if it matches then i do the registration otherwise not now is i am doing everything right or not ?? please tell me, is there something wrong in my approach

Upvotes: 0

Views: 802

Answers (1)

dilas
dilas

Reputation: 11

 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
      }
    });

//Hope this helps

Upvotes: 1

Related Questions