Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Validating a OTP without storing it anywhere like database and Sessions

I have generated a eight digit random OTP and sent it to mail using servlet. I want to validate the OTP at the next page without storing it anywhere like database and session. How can I do this?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This technique is done using the following steps:

  • Create a cryptographic hash (HMAC) of the phone number, the generated OTP and the expiry timestamp combined.
  • Append the expiry timestamp with the hash and Send the hash to the
    user as the response of the first request.
  • Once the user gets the SMS, the user sends back the hash, the phone number and the OTP in the second request.
  • The server verifies the OTP by hashing the phone number, OTP sent by the
    user, and the expiry timestamp that was appended with the hash, the user sent back. Using the same key and same algorithm.
  • If the expiry timestamp is valid and still in the future. And the
    newly generated hash matches the one sent by the user. Then the OTP
    is authentic.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading