New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

2fa-auth-v1

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

2fa-auth-v1

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

  • 1.0.2
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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.

Keywords

FAQs

Package last updated on 29 May 2024

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

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc