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 | 5 | 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.5.4 | runtime |
jestEnvironment{
"local_name": "jest",
"alias": false,
"peer_metadata": null
} | ^29.7.0 | development |
eslintEnvironment{
"local_name": "eslint",
"alias": false,
"peer_metadata": null
} | ^9.21.0 | development |
globalsEnvironment{
"local_name": "globals",
"alias": false,
"peer_metadata": null
} | ^16.0.0 | development |
@eslint/jsEnvironment{
"local_name": "@eslint/js",
"alias": false,
"peer_metadata": null
} | ^9.21.0 | development |
eslint-plugin-jestEnvironment{
"local_name": "eslint-plugin-jest",
"alias": false,
"peer_metadata": null
} | ^28.11.0 | development |
Source distribution
{
"shasum": "426b9e1c4c329641c885287410b97c862e669276",
"tarball": "https://registry.npmjs.org/2fa-util/-/2fa-util-1.4.0.tgz",
"fileCount": 10,
"integrity": "sha512-MWo+aZR2OfltNl8UpxxnCVWRFRlsF3J7FXpVinhPBI3mT+T2TyKNfrDlK+jzAWbNHRhTZ1iIrPav93F3vAPpNA==",
"signatures": [
{
"sig": "MEUCIElVtOgyJuC6DB6KAEG/q0dloo97zsdckYk4vnEHimpgAiEAzHKT20Mbm6ZAK8LPIKeKAr+GtVFuhhdpK9aT41y63VY=",
"keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"
}
],
"unpackedSize": 11776
}Observed since 20 Oct, 19:12 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:935f3f1a8d85ccd1fb7cf930ccaf73d2e167d491aa545b5d0f26c59a5efc0d1b