Rajith K
Rajith K

Reputation: 429

Save OTP for verification

I am developing a OTP service to verify users via SMS. To verify the opt message what is the best way to save the OTP? I am thinking of using a caching option like Redis.

Thank you.

Upvotes: 1

Views: 4332

Answers (1)

You are on the right track. A key-value store like Redis would be the best option for this purpose. You could have simple logic like this in your preferred language:

Create an OTP -> Save it in Redis using SET with an expiry of whatever time you want -> On getting a request check if the key exists, if the value is right, they are verified.

It's better to use Redis for short-lived purposes like verifying user token by email, OTP, etc

Upvotes: 6

Related Questions