Observed since 20 Oct, 19:12 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
2fa-util
Lightweight utility to generate a two-factor TOTP secret with QR code to be used by authenticators such as Google or Microsoft Authenticator.
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.
otplib options.otplib and qrcode under the hood).npm install 2fa-util
const { generateSecret, verify } = require('2fa-util');
(async () => {
// 1. Generate a Secret and QR Code
const { secret, qrcode, otpauth } = await generateSecret('john.doe@example.com', '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);
})();
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
});
generateSecret(label, [issuer])Generates a new TOTP secret and corresponding QR code.
(string): The username or account identifier (e.g., email).(string, optional): The name of your application or company.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.
(string): The 6-digit token provided by the user.(string): The user's stored secret key.(Object, optional): Configuration object passed to otplib.boolean (true if valid, false otherwise).generate(secret)Generates the current token for a given secret (useful for testing or dev tools).
(string): The secret key.string (The current 6-digit token).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
MIT © John Ho
npm · 1 observations shown. Missing days are unknown.
| Date / source period | Value | Observed at |
|---|---|---|
| 2026-10-22 | 631 | 2026-10-22T21:23:42.2534837Z |
| Package / target | Requirement | Relationship |
|---|---|---|
otplibEnvironment{
"local_name": "otplib",
"alias": false,
"peer_metadata": null
} | ^12.0.1 | runtime |
qrcodeEnvironment{
"local_name": "qrcode",
"alias": false,
"peer_metadata": null
} | ^1.4.4 | runtime |
jestEnvironment{
"local_name": "jest",
"alias": false,
"peer_metadata": null
} | ^27.3.1 | development |
eslintEnvironment{
"local_name": "eslint",
"alias": false,
"peer_metadata": null
} | ^8.1.0 | development |
eslint-plugin-jestEnvironment{
"local_name": "eslint-plugin-jest",
"alias": false,
"peer_metadata": null
} | ^25.2.2 | development |
Source distribution
{
"shasum": "3c4ba97e85a0247d8057ff147c49fcce0b3e7dbb",
"tarball": "https://registry.npmjs.org/2fa-util/-/2fa-util-1.1.1.tgz",
"fileCount": 9,
"integrity": "sha512-DplBQOPMheQuutnf9friLipU9XKinEFn2wQBB6RT6bnrPbDOhY/wXB4A8kH3yhagb7Z/sqIOrAwuXTeDY0OmIA==",
"signatures": [
{
"sig": "MEQCIEgNi1SXjx/Rmhru9SSg//TiM0DpekuNHTw0nut8bNXgAiArmbjyO/uaD6cdI5npKjsuFXFIuL6kNb7YvWrdEpssng==",
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
}
],
"unpackedSize": 11088,
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhuebaCRA9TVsSAnZWagAA/KgP/1zNZlYqTrqRZeCptNMg\nH/LziGgUXlCLhZdf8m6PuCilgQEwz1qSA2/xY6V+k+hGMGd837X1Gw5rGjDw\nUwM1d9WfjdW+Pj0G5YN8YBooazgvisuGuE9hecWeZa+TooQmciwj6MYQ3c0G\nJ/uQmZ/4C8TSzAi+PlpJRfx3SX/bQVs8uItsdYRdsIpS5NHrLhAA+GtsUnPm\n0b85yfYv8ccCne4LD4n1fs7MNOdLrXVuLYg8rKtKoF01gwmJhBQWzCL0gb98\n1HHtF256hihb4K8/8Rcxr/cDcYJL1U3yRfLtNxOHZrH0Q9pYd+vrVOMMN8/9\nDJ2ep1JOEysk46PiW0O1B1QQKK4yu5COXdn4b51UOzvmu9rUlbk/y3fFHj9i\nXqHo6zqxZYlBNjjgqsQ5ZLtx6oHjCO+XA68dmB/rrD/lklRoXtr2BggW3A6P\nIb6uP8krtd16eghC4IcX3wihns53oetZYS6sVFJNwQ3xHMyDU3XMsE1fN75f\nXW78yPkGX41LADHgBLLBrvdKnwuYWWX1uNA4S0aTdh8/NJXszj81sq81aTBu\nadyvhiw9fN2aPy6BakHu7N4tzFzBb7WpRg9f37AIFdqb4GnweJoI2BvzRS26\nbjgYmonnSZf2RY7NcFBlAwN4dTK4rh7qsaA/SHH9IA3W9As3biWiKZdY2G4M\niaS6\r\n=PX+y\r\n-----END PGP SIGNATURE-----\r\n"
}Observed since 20 Oct, 19:12 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:d484740aecc6865b8f6f463e1ae8ce95b2c918f16a3e2f796911fc7e4a714c71