Two-factor authentication (2FA) codes are everywhere – Facebook, Gmail, GitHub, Binance. Usually they live in an app on your phone. But sometimes you need a code on a computer, your phone is in another room, or you're setting up an account and only have the secret key.

There are online tools for this, but most of them don't make it clear what happens to the secret key you paste in. That key is the most sensitive part of your 2FA – anyone who has it can generate your codes forever.

So I built 2FA Code Generator with one rule: the secret key never leaves your browser.

How a 2FA (TOTP) code is made

Almost every "authenticator app" code is a TOTP – a Time-based One-Time Password, defined in RFC 6238. It only needs two things:

  1. The secret key the website gave you when you turned on 2FA (usually Base32, like JBSWY3DPEHPK3PXP, or inside a QR code)
  2. The current time, divided into 30-second steps

Both the website and your authenticator run the same calculation, so they get the same 6-digit code – no network connection needed.

The whole thing runs on Web Crypto

Modern browsers ship a built-in cryptography API (crypto.subtle), so there's no need for any server or external library to calculate the code. Here's the core of it:

async function totp(secretBytes, digits = 6, period = 30) { const counter = Math.floor(Date.now() / 1000 / period); // 8-byte big-endian counter const buf = new ArrayBuffer(8); const view = new DataView(buf); view.setUint32(0, Math.floor(counter / 2 ** 32)); view.setUint32(4, counter >>> 0); // HMAC-SHA1 with the secret key const key = await crypto.subtle.importKey( 'raw', secretBytes, { name: 'HMAC', hash: 'SHA-1' }, false, ['sign'] ); const h = new Uint8Array(await crypto.subtle.sign('HMAC', key, buf)); // Dynamic truncation (RFC 4226) const o = h[h.length - 1] & 15; const bin = ((h[o] & 127) << 24) | (h[o + 1] << 16) | (h[o + 2] << 8) | h[o + 3]; return String(bin % 10 ** digits).padStart(digits, '0'); } 

Add a small Base32 decoder in front of it, and that's a complete authenticator in a few dozen lines.

Privacy you can check yourself

Instead of asking you to trust me, you can verify it:

  • Open your browser's DevTools → Network tab, paste a key, and watch: no request carries your key.
  • Or load the page, turn off your Wi-Fi, and keep generating codes – it still works.
  • Quick-share links use the URL hash (#key=…), which browsers never send to the server.

Features

  • Live 6-digit code with a 30-second countdown and a preview of the next code
  • QR code scanner: use your camera, upload a screenshot, or just press Ctrl+V to paste a QR image
  • Supports otpauth:// links, 6 or 8 digits and 30 or 60-second periods
  • "Check a code" – type a code and see if it matches the current, previous or next one
  • Optionally save accounts in your browser's local storage (never on a server)
  • Works on phone, tablet and desktop – no app, no sign-up

A word of caution

An online authenticator is great for quick access, but please still:

  • Keep your secret keys in a proper authenticator app as well
  • Save your backup/recovery codes somewhere safe and offline
  • Never share a 2FA code with anyone who messages or calls you

Try it

👉 2fa.christmas – test it with the demo key JBSWY3DPEHPK3PXP.

There are also step-by-step guides for turning on 2FA for Facebook, Google, GitHub and more.

I'd love your feedback – what would make an online 2FA tool more useful (or more trustworthy) for you?