How to Create Your Own One-Time Password (OTP) Service?

0
15
Asked By TechieTurtle99 On

I'm planning to set up my own OTP service for my website because I'm tired of paying for email sending services. I'm curious about how to effectively manage the backend for this. Should I store the OTPs in a database as hashed values? Once a user inputs their OTP, would I compare the hash to proceed? Is there a more efficient method to implement this that I may be overlooking?

5 Answers

Answered By SecureDevPro On

A solid approach is to only generate the OTP when necessary, like for email or phone verifications. Here's a simple flow: generate a random OTP, store its hashed version alongside the user's identifier and an expiration time (e.g., 5 minutes). Send the plain OTP to the user. When they input it, check if it's valid and not expired by comparing the hashes. Don't forget to invalidate it after using! You could even automate cleanup for expired OTPs using cron jobs or Redis for better efficiency.

Answered By EmailExpert90 On

Honestly, if you're not careful with how you manage your email sending domain, creating an OTP service could lead to more problems than it solves. I'd focus on that aspect first if you pursue this direction.

TechieTurtle99 -

If I'm just sending OTPs, do you think the domain reputation will be less of an issue?

Answered By CodeNinja42 On

Rolling your own OTP service might not be the best route to take. It's often easier to use established solutions since they handle a lot of the security and reliability aspects for you. But if you really want to learn, it can be a valuable experience!

CuriousCoder123 -

That makes sense. I've set up link verification before, so I'm thinking an OTP service could be a fun challenge!

DevNewbie2021 -

Yeah, I'd love to learn more on this too!

Answered By SimpleSolutionGuy On

Have you considered using services like AWS Cognito? It could end up being cheaper and save you a ton of development headaches later.

Answered By HashMaster01 On

I use a link verification system instead of OTPs. Essentially, I generate a unique hash for each user and email them a link containing that hash. When they click on the link, it verifies against what's stored on the server. If they need to resend, it clears the old hash and creates a new one. I can share more details if you're interested, just busy at work right now!

TechieTurtle99 -

That sounds interesting! How are you storing the hashes—do you keep them in a database?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.