Catalog npm
Back to packageRELEASE DETAILS

1.0.1

npm

2fa-auth-v1

A simple npm package for 2FA (Two-Factor Authentication) using TOTP (Time-Based One-Time Password) and QR codes.

otplibqrcode
Published29 May 2024
Direct dependencies2
Transitive dependenciesNot calculated

README

Current package documentation

2FA Authentication

A simple npm package for 2FA (Two-Factor Authentication) using TOTP (Time-Based One-Time Password) and QR codes.

Installation

Install the package using npm:

npm install 2fa-auth

Usage

1. Generating the QR Code

Use the generate.js script to generate a QR code and save the secret.

generate.js

const fs = require('fs');
const TwoFactorAuth = require('2fa-auth');

const twoFA = new TwoFactorAuth();
const user = 'example@gmail.com';

twoFA.generateQRCode(user, (err, qrCodeImage) => {
  if (err) {
    console.error('Failed to generate QR code:', err);
  } else {
    console.log('QR Code Image:', qrCodeImage);

    // Save the secret to a file
    const secret = twoFA.secret;
    
    console.log('Secret Key ', secret);
  }
});

2. Verifying the Token

Use the verify.js script to verify the token generated by a 2FA app using the secret key.

verify.js

const TwoFactorAuth = require('2fa-auth');

const secret = 'BQKBELJ3B4BHYJQF';
const twoFA = new TwoFactorAuth(secret);


const token = '777427';

const isValid = twoFA.verifyToken(token);
console.log('Is Token Valid?', isValid);

License

This project is licensed under the MIT License. See the LICENSE file for details.

Make sure to replace 'example@gmail.com' and 'BQKBELJ3B4BHYJQF' with actual user email and secret key respectively, and adjust the usage examples as needed. Additionally, you should include a LICENSE file in your project directory if you haven't already, containing the text of the MIT License or whichever license you choose.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 2

Native requirements
2 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
otplib
Environment
{
  "local_name": "otplib",
  "alias": false,
  "peer_metadata": null
}
^12.0.1runtime
qrcode
Environment
{
  "local_name": "qrcode",
  "alias": false,
  "peer_metadata": null
}
^1.5.3runtime

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "584da211b0dda929e3564adb4311919a167daca9",
  "tarball": "https://registry.npmjs.org/2fa-auth-v1/-/2fa-auth-v1-1.0.1.tgz",
  "fileCount": 5,
  "integrity": "sha512-XDL9D0fFELCo580ILiDTUmvfcGtpp5z2z8dotH3GSmxbEa5tiLKP/AK4QTAHqAQ2fDhfbybPAjfCazrUOVa/lw==",
  "signatures": [
    {
      "sig": "MEYCIQCkb7o1f7LGh+OBW2WrHfN3uJLf4tbu91AOIDezYfkM9wIhAMk6w9TM4q6tAVBfJ0L98XrjXZYnTxNzWxXM1PLGBTAz",
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
    }
  ],
  "unpackedSize": 3395
}

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:12 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:eaf973301c3fbb2a837891fd98bd624fb9f8142b56e8bcfb25c6cf5e392b6ed5

Other collected versions

1.0.229 May1.0.029 MayView all collected versions →