Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One time Password in Node js [closed]

I want to use OTP for my node-express API. Right now I am able to personalize things using username and password, but would like to do it using mobile number and OTP. What references can I use for this?

like image 481
Nimit Bedi Avatar asked Oct 28 '25 08:10

Nimit Bedi


1 Answers

If you want to just verify the phone by sending and OTP and then asking for it then I don't think you should go for Speakeasy.

Speakeasy is mainly for TOTP and HOTP which are more like 2 Factor Authentication (generate OTPs every 30 seconds, for example).

But since you want to verify a user's phone once all you need to do is:

  1. Generate any random n-digit number and save it in a table in DB mapped to user with creation time.
  2. Send this to the user's phone. You can use any service. I personally use twilio.
  3. When user enters the OTP, check the current time against the creation time and see if it's valid.
  4. Handle the cases: a) if valid: mark user as verified b) if invalid: whatever you want to do.
like image 122
Abhyudit Jain Avatar answered Oct 29 '25 22:10

Abhyudit Jain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!