![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
2fa-auth-v1
Advanced tools
A simple npm package for 2FA (Two-Factor Authentication) using TOTP (Time-Based One-Time Password) and QR codes.
A simple npm package for 2FA (Two-Factor Authentication) using TOTP (Time-Based One-Time Password) and QR codes.
Install the package using npm:
npm install 2fa-auth
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);
}
});
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);
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.
FAQs
A simple npm package for 2FA (Two-Factor Authentication) using TOTP (Time-Based One-Time Password) and QR codes.
We found that 2fa-auth-v1 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.