npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

2fa-util

v1.5.0

Published

Lightweight utility to generate a two-factor TOTP secret with QR code to be used by authenticators such as Google or Microsoft Authenticator.

Readme

2fa-util

Build Status License NPM Version

A lightweight, robust Node.js utility for generating Two-Factor Authentication (TOTP) secrets, QR codes, and verifying tokens. Compatible with Google Authenticator, Microsoft Authenticator, and Authy.

🚀 Live Demo

Features

  • Easy Setup: Generate a secret and QR code in one function call.
  • Standard Compatible: Works with any RFC 6238 compliant authenticator app.
  • Flexible Verification: Supports custom windows, steps, and other otplib options.
  • Zero-Dependency (Runtime): Bundles necessary logic efficiently (uses otplib and qrcode under the hood).

Installation

npm install 2fa-util

Usage

Basic Example

const { generateSecret, verify } = require('2fa-util');

(async () => {
    // 1. Generate a Secret and QR Code
    const { secret, qrcode, otpauth } = await generateSecret('[email protected]', 'MyApp');
    
    console.log('Secret:', secret);
    console.log('QR Code Data URL:', qrcode); // Display this in an <img src="...">

    // ... User scans QR code ...

    // 2. Verify a Token
    const userToken = '123456'; // Input from user
    const isValid = verify(userToken, secret);

    console.log('Is Valid:', isValid);
})();

Advanced Verification (Custom Options)

You can pass standard otplib options to the verify function, such as window (for clock drift) or step.

const isValid = verify(token, secret, {
    window: 1, // Allow 1 step before/after (approx +/- 30sec)
    step: 60   // Custom step size in seconds
});

API Reference

generateSecret(label, [issuer])

Generates a new TOTP secret and corresponding QR code.

  • label (string): The username or account identifier (e.g., email).
  • issuer (string, optional): The name of your application or company.
  • Returns: Promise<Object>
    • secret: The base32 encoded secret key.
    • qrcode: A Data URI string (base64) of the QR code image.
    • otpauth: The raw otpauth:// URL.

verify(token, secret, [options])

Verifies a TOTP token against a secret.

  • token (string): The 6-digit token provided by the user.
  • secret (string): The user's stored secret key.
  • options (Object, optional): Configuration object passed to otplib.
  • Returns: boolean (true if valid, false otherwise).

generate(secret)

Generates the current token for a given secret (useful for testing or dev tools).

  • secret (string): The secret key.
  • Returns: string (The current 6-digit token).

Development

Clone the repository and install dependencies:

git clone https://github.com/jzhobes/2fa-util.git
cd 2fa-util
npm install

Run tests:

npm test

Run linting:

npm run lint

License

MIT © John Ho