A simple library for managing OTPs for all your applications. It helps with the generation, storage and verification of OTPs.
These instructions will give you a copy of the project up and running on your local machine for development and testing purposes.
Requirements:
- Node.js (version >= 16.0.0)
Install with:
NPM:
npm install @otp-forge/otp-forge
Yarn:
yarn add @otp-forge/otp-forge
PNPM:
pnpm add @otp-forge/otp-forge
pnpm
Initialize the OTPManager with the required configuration options:
const OTPManager = require("@otp-forge/otp-forge");
// In memory storage
const passwordResetOTPManager = new OTPManager({
// Configuration options
purpose: "password-reset", // Purpose of the OTP
otpLength: 6, // Length of the OTP
expirationTime: 300, // Time to live in seconds
});
Generate an OTP:
const otp: number = await passwordResetOTPManager.generateOTP();
Verify an OTP:
const isValid: boolean = await passwordResetOTPManager.verifyOTP(otp);
Warning: The default store is in-memory, which means that the OTPs will be lost when the application is restarted. To use a persistent store, you can use one of the supported stores or build your own.
We use Semantic Versioning for versioning.
This project is licensed under the MIT License