Skip to content

Instantly share code, notes, and snippets.

@lalosh
Last active January 31, 2025 09:44
Show Gist options
  • Save lalosh/4b975f8ab28dd85e17a684d3152f0c3e to your computer and use it in GitHub Desktop.
Save lalosh/4b975f8ab28dd85e17a684d3152f0c3e to your computer and use it in GitHub Desktop.
TOTP generator in case you lost your phone
/**
* how to use?
* install node.js + npm, copy the code in a clean folder,
* run `npm i totp-generator`
* run `node main.mjs <OTP-CODE>`
* you must have the OTP code from the service provider itself (which you get when you did the Multi-factor setup)
*/
import { TOTP } from "totp-generator";
const { otp, expires } = TOTP.generate(process.argv[2]);
console.log(
`Your OTP is ${otp} and expires in ${Math.abs(new Date().getTime() - expires) / 1000} seconds`,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment