@krishna1584/otp-handler
v1.0.0
Published
It generates OTP and verify it.
Maintainers
Readme
OTP Handler
A simple and lightweight Node.js package for generating and verifying One-Time Passwords (OTP).
Features
- Generate random numeric OTPs of any specified length
- Verify OTPs against the generated value
- Lightweight with no external dependencies
- Error handling included
Installation
npm install @krishna1584/otp-handlerUsage
const { otpGenerator, otpVerify } = require('@krishna1584/otp-handler');
// Generate a 6-digit OTP
const otp = otpGenerator(6);
console.log('Generated OTP:', otp);
// Verify the OTP
const userInput = '123456'; // User's input
const isValid = otpVerify(userInput);
console.log('OTP is valid:', isValid);API
otpGenerator(length)
Generates a random numeric OTP.
- Parameters:
length(number): The desired length of the OTP
- Returns: String - The generated OTP
- Throws: Error if generation fails
otpVerify(userOtp)
Verifies if the provided OTP matches the generated one.
- Parameters:
userOtp(string): The OTP to verify
- Returns: Boolean -
trueif valid,falseotherwise - Throws: Error if verification fails
Author
Krishna
License
ISC
