Skip to content

Instantly share code, notes, and snippets.

View krrskl's full-sized avatar
🏠
Working from home

Ruben Carrascal krrskl

🏠
Working from home
View GitHub Profile
@theanam
theanam / otpverify.js
Last active June 14, 2024 15:01
OTP verification without database, full sample source code
const otpGenerator = require("otp-generator");
const crypto = require("crypto");
const key = "verysecretkey"; // Key for cryptograpy. Keep it secret
function createNewOTP(phone){
// Generate a 6 digit numeric OTP
const otp = otpGenerator.generate(6, {alphabets: false, upperCase: false, specialChars: false});
const ttl = 5 * 60 * 1000; //5 Minutes in miliseconds
const expires = Date.now() + ttl; //timestamp to 5 minutes in the future
const data = `${phone}.${otp}.${expires}`; // phone.otp.expiry_timestamp