2fa-util
v1.2.0
Published
Lightweight utility to generate a two-factor TOTP secret with QR code to be used by authenticators such as Google or Microsoft Authenticator.
Downloads
2,898
Maintainers
Readme
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.
Usage
const {generateSecret, verify} = require('2fa-util');
await generateSecret('John Doe', 'Company');
// Output:
// {
// qrcode: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMQAAADECAYAAADApo5rAAAAAklEQVR4AewaftIAAAjgSURBVO3BQYolyZIAQdUg739lnWIWjq0cgveyun9jIvYHa63/97DWOh7WWsfDWut4WGsdD2ut42GtdTystY6HtdbxsNY6HtZax8Na63hYax0Pa63jYa11PKy1jh8+pPI3Vdyo3FRMKr+pYlKZKiaVm4pJ5Y2KG5Wp4hMqf1PFJx7WWsfDWut4WGsdP3xZxTepfKJiUnmjYlK5qbipuKmYVCaVqWJSmSomlaliqphUpopPVHyTyjc9rLWOh7XW8bDWOn74ZSpvVLyhMlXcVEwq36TyiYqbiknljYoblRuVqeITKm9U/KaHtdbxsNY6HtZaxw//MSpTxaRyUzGpTBVvqEwVb1RMKp9QuamYVKaK/7KHtdbxsNY6HtZaxw//MRWTylQxqUwqNypTxaRyo/KJikllqphUpooblaliUrmp+F/2sNY6HtZax8Na6/jhl1X8TSpTxRsVk8qNyhsVk8pNxU3FTcWkMlW8UTGpfKLi3+RhrXU8rLWOh7XW8cOXqfyTKiaVqeITFZPKVDGpvFExqUwVk8pUMalMFZPKVDGpTBWfUPk3e1hrHQ9rreNhrXX88KGKfxOVT6hMFZPKb1KZKj5RMam8UTGpTBU3Ff9LHtZax8Na63hYax0/fEhlqphUvqliqvhExaTyRsWkMlXcVNyo3FRMKlPFGyo3FW+ofFPFb3pYax0Pa63jYa11/PChikllqphUbipuVD5RcVMxqUwVNxWTylQxqdxUTCqfqJhUpopJZVKZKt6ouFF5Q2Wq+MTDWut4WGsdD2ut44cPqUwVNxWTyqTyRsWk8obKVDFV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rHw1rreFhrHQ9rreNhrXX8HySbwqpKn0H+AAAAAElFTkSuQmCC',
// otpauth: 'otpauth://totp/Company:John%20Doe?secret=P4IU2RIZBBFEGDYD&period=30&digits=6&algorithm=SHA1&issuer=Company',
// secret: 'P4IU2RIZBBFEGDYD'
// }
await verify('<token from authenticator app>', '<secret>');
// Output: true/false