Socket
Socket
Sign inDemoInstall

generateotp-ts

Package Overview
Dependencies
71
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    generateotp-ts

A TypeScript library for generating and verifying OTPs using JWT


Version published
Maintainers
1
Created

Readme

Source

generateotp-ts

A TypeScript library for generating and verifying One-Time Passwords (OTPs) using JSON Web Tokens (JWT).

Features

  • Generate n-digit OTPs
  • Set custom expiration time for OTPs
  • Verify OTPs with tokens
  • Encode and decode OTPs using JWT

Installation

Install generateotp-ts using npm:

npm install generateotp-ts

Usage

Import and use the generateOtp and verifyOtp functions in your TypeScript or JavaScript project:

import { generateOtp, verifyOtp } from "generateotp-ts";

// Generate a 6-digit OTP with a 5-minute expiration time
const { otp, token } = generateOtp(6, "5m");

console.log("Generated OTP:", otp);
console.log("Token:", token);

// Verify the OTP with the token
const isValidOtp = verifyOtp(otp, token);

console.log("Is OTP valid?", isValidOtp);

generateOtp()

The generateOtp() function generates an n-digit OTP and returns an object containing the generated OTP and its corresponding JWT-encoded token.

Function signature:

function generateOtp(
  digits: number,
  expiration: string | number | undefined = undefined,
  secret: string = ""
): { otp: number; token: string };

verifyOtp()

The verifyOtp() function verifies the provided OTP against the JWT-encoded token and returns true if it's valid, or false if it's invalid or expired.

Function signature:

function verifyOtp(otp: number, token: string, secret: string = ""): boolean;

Keywords

FAQs

Last updated on 19 Jun 2023

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc