Socket
Book a DemoInstallSign in
Socket

otp-simple-generator

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

otp-simple-generator

OTP Codes generator and verifier

1.0.5
latest
npmnpm
Version published
Weekly downloads
26
-10.34%
Maintainers
1
Weekly downloads
 
Created
Source

otp-simple-generator

A simple and lightweight OTP (One-Time Password) generator, retriever, and verifier for JavaScript projects. Works with any JavaScript framework or library (React, Vue, Angular, Node.js, etc.).

Installation

npm install otp-simple-generator

Usage

Import the package:

import otp from "otp-simple-generator";

The package provides three main methods:

otp.generate(phone, length = 4, expire = 10)

Generates an OTP for the given phone number.

  • phone (string): Phone number to associate with the OTP.
  • length (number, optional): Length of the OTP (default is 4 digits).
  • expire (number, optional): Expiration time in minutes (default is 10 minutes).

Returns an object containing success status, message, and the OTP data.

otp.get(phone)

Retrieves the OTP data stored for the given phone number.
Returns the OTP data object or null if none found.

otp.verify(phone, otp)

Verifies the provided OTP for the given phone number.
Returns an object with success status and messages in both English and Arabic.

Example

const generated = otp.generate("+964123456789", 6, 5);
console.log(generated);

const data = otp.get("+964123456789");
console.log(data);

const verified = otp.verify("+964123456789", "123456");
console.log(verified);

Output Example

otp.generate("+964123456789", 6, 5)

{
  "success": true,
  "message": "OTP generated successfully",
  "data": {
    "otp": 123456,
    "expire": "2025-07-28T12:34:56.789Z",
    "phone": "+964123456789"
  }
}

otp.get("+964123456789")

{
  "otp": 123456,
  "expire": "2025-07-28T12:34:56.789Z",
  "phone": "+964123456789"
}

otp.verify("+964123456789", "123456")

{
  "success": true,
  "message": "OTP code verified successfully",
  "arMessage": "تم التحقق من رمز التأكيد بنجاح"
}

How It Works

This package uses simple-json-db as a local JSON key-value store for OTP data.

License

MIT © Ali Hammad

Keywords

OTPIQ

FAQs

Package last updated on 28 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.