DEV Community

Cover image for OTP Verification using Hash
Nazmul Hossain
Nazmul Hossain

Posted on

OTP Verification using Hash

Most of the time cache memory or database used to verify OTP. It's expensive operation. We can verify OTP without using database or cache memory.

Today I will explain how to verify OTP without cache memory/ database operation.

OTP requested user send request with mobile number. Then requested number, generated OTP(using otp-generator) is used to create hash value using sha256. Then hash value is used for OTP request response & preserve it on frontend. Generated OTP will send to requested users Mobile number.

After getting OTP, user now verify OTP with 2nd request. On the 2nd request OTP, Mobile No & Hash will be sent to the server to verify. Using mobile no & OTP we will generate new hash. New hash value will be compared with requested hash value. If both hash value matched then OTP is verified.

Code: https://github.com/bilashcse/otp-verification

Top comments (0)