Mychael Go

TOTP Generator

A one-time-password generator that runs entirely in your browser.

The problem

Generating a two-factor code from a raw secret usually means pasting that secret into a site you have to trust, or installing an app.

What I did

  • Implemented TOTP (RFC 6238) with the Web Crypto API: Base32 decoding, HMAC-SHA1 and dynamic truncation, so the secret never leaves the browser and is never stored.
  • Built a mobile-friendly UI in React with Tailwind CSS and shadcn/ui: configurable digits and time window, a countdown bar and one-tap copy.
  • Tested the algorithm against the official RFC 6238 test vectors with Vitest and React Testing Library.

Screenshots

TOTP Generator showing code 724963 for the example secret JBSWY3DPEHPK3PXP, with digits 6, a 30-second window and a countdown
The live app with the public example secret JBSWY3DPEHPK3PXP.
totp.ts on GitHub with base32Decode and generateTotp using crypto.subtle HMAC-SHA1
The core: Base32 decoding and HMAC-based code generation with Web Crypto.

Reading this with an AI tool? Get this page as Markdown.