{"_id":"2factor-auth","_rev":"6-b2359382140caf3c2aea282840cb6659","name":"2factor-auth","description":"TOTP + HOTP library, aimed for communication between servers handing 2FA","dist-tags":{"latest":"1.0.2"},"versions":{"0.2.0":{"name":"2factor-auth","version":"0.2.0","description":"TOTP + HOTP library, aimed for communication between servers handing 2FA","main":"lib/2FA.js","repository":{"type":"git","url":"git://github.com/simontabor/Saber-Tecnologias/2fa-server-node.git"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["auth","two-factor","2fa","TOTP","HOTP","Token"],"author":{"name":"Saber Tecnologias Educacionais e Sociais - Leonardo Pereira","email":"jlcvp@cin.ufpe.br","url":"www.sabertecnologias.com.br"},"license":"LGPL-3.0","dependencies":{"thirty-two":"0.0.2"},"gitHead":"6f467d3ff87c1d2f5de024bc17e419cb452e5267","_id":"2factor-auth@0.2.0","_shasum":"33a51b691114970064543de0a0fc484998e2d6b7","_from":".","_npmVersion":"2.15.1","_nodeVersion":"4.4.4","_npmUser":{"name":"jlcvp","email":"jlcvp@cin.ufpe.br"},"dist":{"shasum":"33a51b691114970064543de0a0fc484998e2d6b7","tarball":"https://registry.npmjs.org/2factor-auth/-/2factor-auth-0.2.0.tgz","integrity":"sha512-ea5vJczMq00XdB034tPjMbMS5PFGsQ4t/1rn8JGRjgZz+AS98aeMrPiENOL3iNsaXXwFlduIp81nMlx2tEX3nQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCbFbtUhcD67j5iNge18qaaimyWr9EE1lIBPk7ZipmXQgIgWro+PRbIoL+H8jsgk4FWK6jviOcJyCgaZxrSmtkMtiI="}]},"maintainers":[{"name":"jlcvp","email":"jlcvp@cin.ufpe.br"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/2factor-auth-0.2.0.tgz_1466176136646_0.3399616067763418"},"directories":{}},"1.0.0":{"name":"2factor-auth","version":"1.0.0","description":"TOTP + HOTP library, aimed for communication between servers handing 2FA","main":"lib/2FA.js","repository":{"type":"git","url":"git+ssh://git@github.com/jlcvp/2fa-server-node.git"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["auth","two-factor","2fa","TOTP","HOTP","Token"],"author":{"name":"Leonardo \"Leu\" Pereira"},"license":"MIT","dependencies":{"thirty-two":"^1.0.2"},"_id":"2factor-auth@1.0.0","gitHead":"960c8a09cc3cac3b5e34b62a2cd51762eb1756f0","bugs":{"url":"https://github.com/jlcvp/2fa-server-node/issues"},"homepage":"https://github.com/jlcvp/2fa-server-node#readme","_nodeVersion":"20.11.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-7fs+P4pxJRbT3K2PBKctFUNv+qLMABXWvvDi8H7QUkQE7pmEz3DEmEj1zC5f/eGxRRRxNVb7AHfuY/gx3QnIqg==","shasum":"12092bcfac23e0ded3c74f393a01f5f5e683d1d2","tarball":"https://registry.npmjs.org/2factor-auth/-/2factor-auth-1.0.0.tgz","fileCount":4,"unpackedSize":11044,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDmVfhxGgeO4sHReL5FpoYbd69FlvSBfdQcIpJEnmPKYQIgZeGitzFwOrb/jS35XbqL0MYWVev9dSsPf3/2KmGDVLI="}]},"_npmUser":{"name":"jlcvp","email":"jlcvp@cin.ufpe.br"},"directories":{},"maintainers":[{"name":"jlcvp","email":"jlcvp@cin.ufpe.br"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/2factor-auth_1.0.0_1716475041359_0.6776436093102203"},"_hasShrinkwrap":false},"1.0.1":{"name":"2factor-auth","version":"1.0.1","description":"TOTP + HOTP library, aimed for communication between servers handing 2FA","main":"lib/2FA.js","repository":{"type":"git","url":"git+ssh://git@github.com/jlcvp/2fa-server-node.git"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["auth","two-factor","2fa","TOTP","HOTP","Token"],"author":{"name":"Leonardo \"Leu\" Pereira"},"license":"MIT","dependencies":{"thirty-two":"^1.0.2"},"_id":"2factor-auth@1.0.1","gitHead":"6b28cec313a7138ec66b7a9b243981eb88bb6b0a","bugs":{"url":"https://github.com/jlcvp/2fa-server-node/issues"},"homepage":"https://github.com/jlcvp/2fa-server-node#readme","_nodeVersion":"20.11.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-fQ7iE8t0C1a3Dd9DIGb/3/pdA2TWWecCAgPRZUHjmzdbl3TtAg+9M+atwO0SIej8qxPj560JHChzBTo5kcjIHg==","shasum":"cd06beac628e00ae0582815a82a333045d0d60ae","tarball":"https://registry.npmjs.org/2factor-auth/-/2factor-auth-1.0.1.tgz","fileCount":4,"unpackedSize":12472,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEXR7jpT/HtvZqhuKQ2/3IUqBazkigaASHUZ7pD0iZkaAiAV2grggy32oyI4vfLVRzULfvxANnZ+hd4suEtPW88VEQ=="}]},"_npmUser":{"name":"jlcvp","email":"jlcvp@cin.ufpe.br"},"directories":{},"maintainers":[{"name":"jlcvp","email":"jlcvp@cin.ufpe.br"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/2factor-auth_1.0.1_1716494812127_0.3108167130692374"},"_hasShrinkwrap":false},"1.0.2":{"name":"2factor-auth","version":"1.0.2","description":"TOTP + HOTP library, aimed for communication between servers handing 2FA","main":"lib/2FA.js","repository":{"type":"git","url":"git+ssh://git@github.com/jlcvp/2fa-server-node.git"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["auth","two-factor","2fa","TOTP","HOTP","Token"],"author":{"name":"Leonardo \"Leu\" Pereira"},"license":"MIT","dependencies":{"thirty-two":"^1.0.2"},"_id":"2factor-auth@1.0.2","gitHead":"31184e2ca81381ea71f263e0b89f2b4d7c962b7d","bugs":{"url":"https://github.com/jlcvp/2fa-server-node/issues"},"homepage":"https://github.com/jlcvp/2fa-server-node#readme","_nodeVersion":"20.11.1","_npmVersion":"10.2.4","dist":{"integrity":"sha512-o3lDsUkN/xnYw8k0b2sO3a6aGFIAjCKxAJDfpuvvWljCyPX4+isyCxxfdcaF8PZ0blrUHq4ipKUt2a8g0vYyAg==","shasum":"287b487d3f5c3d9c944e78ce0fa2b7c53a6937db","tarball":"https://registry.npmjs.org/2factor-auth/-/2factor-auth-1.0.2.tgz","fileCount":4,"unpackedSize":12473,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE6DKrBZdbY3MW49CgxTxzBRbaY5kkK7PW1fgbtYEk0gAiEArdgvBSjRA9SUYhD4zCSRfgUJEKIUF/6LZFRfSEWSW7w="}]},"_npmUser":{"name":"jlcvp","email":"jlcvp@cin.ufpe.br"},"directories":{},"maintainers":[{"name":"jlcvp","email":"jlcvp@cin.ufpe.br"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/2factor-auth_1.0.2_1716633115714_0.5060251740163697"},"_hasShrinkwrap":false}},"readme":"# 2factor-auth\n\n[![NPM](https://nodei.co/npm/2factor-auth.png?compact=true)](https://nodei.co/npm/2factor-auth/)\n\nModule for generating and verifying 2FA codes (specifically TOTP and HOTP).\n\nAlso contains utilities for handling common 2FA business logic, such as generating backup codes and otpauth urls.\n\n## Install\n```\nnpm install --save 2factor-auth\n```\n\n## Usage\n### with async/await (or promises)\n```javascript\nconst tfa = require('2factor-auth');\n\nfunction registerUserTwoFactor() {\n  // Name of your service (will appear on top of the authenticator app)\n  const serviceName = 'Cool service that is 2FA protected';\n\n  // Account name of the user (will also appear in the authenticator app)\n  const account = 'myUsername@email.com';\n\n  // generate crypto-secure hex key with 32 characters\n  const key = await tfa.generateKeyPromise(32);\n\n  // generate 8 crypto-secure backups codes with in a user-friendly pattern (xxxx-xxxx)\n  // [ '7818-b7b8', '3526-d3f2', 'be3c-5d9f', ... ]\n  const codes = await tfa.generateBackupCodesPromise(8);\n\n  // generate a URL for the user to open in their 2FA app\n  const url = tfa.generateURL(serviceName, account, key);\n  // otpauth://totp/...\n  \n  // send this URL to the user, generate a QR code, etc.\n\n  /** SAVE THE CODES AND KEY IN YOUR BACKEND/DB associated to the user **/\n}\n\nfunction verifyTwoFactorCode(secret_key, receivedCode) {\n\n  // verify the received code without drift\n  const valid = tfa.verifyTOTP(secret_key, receivedCode);\n  \n  // verify the received code with drift (allows for some time difference between the server and the client)\n  const validWithDrift = tfa.verifyTOTP(secret_key, receivedCode, {\n    beforeDrift: 2,\n    afterDrift: 2\n  });\n\n  return valid;\n}\n\n```\n\n\n\n### with Callbacks\n```javascript\nconst tfa = require('2factor-auth');\n\nfunction registerUserTwoFactor(callback) {\n  // Name of your service (will appear on top of the authenticator app)\n  const serviceName = 'Cool service that is 2FA protected';\n\n  // Account name of the user (will also appear in the authenticator app)\n  const account = 'myUsername@email.com';\n\n  // generate crypto-secure hex key with 32 characters\n  tfa.generateKey(32, (err, key) => {\n    if (err) {\n      callback(err);\n      return;\n    }\n\n    // generate 8 crypto-secure backups codes with in a user-friendly pattern (xxxx-xxxx)\n    // [ '7818-b7b8', '3526-d3f2', 'be3c-5d9f', ... ]\n    tfa.generateBackupCodes(8, (err, codes) => {\n      if (err) {\n        callback(err);\n        return;\n      }\n\n      // generate a URL for the user to open in their 2FA app\n      const url = tfa.generateURL(serviceName, account, key);\n      // otpauth://totp/...\n      \n      // send this URL to the user, generate a QR code, etc.\n\n      /** SAVE THE CODES AND KEY IN YOUR BACKEND/DB associated to the user **/\n      callback(null);\n    });\n  });\n}\n\nfunction verifyTwoFactorCode(secret_key, receivedCode) {\n  // verify the received code without drift\n  const valid = tfa.verifyTOTP(secret_key, receivedCode);\n  \n  // verify the received code with drift (allows for some time difference between the server and the client)\n  const validWithDrift = tfa.verifyTOTP(secret_key, receivedCode, {\n    beforeDrift: 2,\n    afterDrift: 2\n  });\n\n\n  return valid;\n}\n```\n","maintainers":[{"name":"jlcvp","email":"jlcvp@cin.ufpe.br"}],"time":{"modified":"2024-05-25T10:31:56.079Z","created":"2016-06-17T15:08:59.270Z","0.2.0":"2016-06-17T15:08:59.270Z","1.0.0":"2024-05-23T14:37:21.505Z","1.0.1":"2024-05-23T20:06:52.259Z","1.0.2":"2024-05-25T10:31:55.895Z"},"keywords":["auth","two-factor","2fa","TOTP","HOTP","Token"],"repository":{"type":"git","url":"git+ssh://git@github.com/jlcvp/2fa-server-node.git"},"author":{"name":"Leonardo \"Leu\" Pereira"},"license":"MIT","readmeFilename":"README.md","homepage":"https://github.com/jlcvp/2fa-server-node#readme","bugs":{"url":"https://github.com/jlcvp/2fa-server-node/issues"}}