K. M. Mukut
Blog · · 4 min read

ChronoCode: a two-factor code generator that keeps nothing

A small, open-source TOTP generator for two-factor authentication. Paste a secret key and get the six-digit code; it runs entirely in your browser, works offline, and never stores or sends your key. Available as a web app and as a Firefox and Chrome extension.

Most accounts worth protecting now ask for a second factor: a six-digit code that changes every thirty seconds. Those codes usually come from an authenticator app on a phone. ChronoCode is a small alternative I wrote that runs in the browser instead: paste the secret key, and the current code appears, generated entirely on your own device.

It is open source, runs as a web app you can install, and is also available as an extension for Firefox and for Chromium-based browsers such as Chrome, Edge and Brave.

How the six digits are made

The codes are time-based one-time passwords (TOTP), an open standard, so ChronoCode produces the same codes as a standard authenticator app. When you turn on two-factor login, the service gives you a secret key, often shown as a QR code with a line of text beneath it. That text is the key, written in Base32.

Inside a dashed boundary labelled inside your browser, key never stored or sent: four steps from your secret key and the current time in 30-second steps, through HMAC-SHA-1 computed with Web Crypto, to six digits that change every 30 seconds
How a time-based one-time password is made. Diagram drawn for this post.

From then on, both sides compute the same code independently. The current time is cut into 30-second steps, and the key and the step number are combined with HMAC-SHA-1, a standard cryptographic hash. Six digits are taken from the result. Because the service knows the key and the time too, it can check your code without anything being sent between your device and the service when the code is made.

ChronoCode does the hashing with the browser’s built-in Web Crypto interface rather than with a hand-written implementation.

A worked example

The standard (RFC 6238) publishes test values, so any implementation can be checked against it. Its test key is the 20 characters 12345678901234567890, and one of its test times is 59 seconds after midnight UTC on 1 January 1970, the moment Unix time starts counting from. Here is every step for that moment:

key (Base32)    GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ
key (bytes)     the 20 characters "12345678901234567890"
time            59 s after 1970-01-01 00:00:00 UTC
time step       floor(59 / 30) = 1, as 8 bytes: 00 00 00 00 00 00 00 01
HMAC-SHA-1      75 a4 8a 19 d4 cb e1 00 64 4e
                8a c1 39 7e ea 74 7a 2d 33 ab
offset          the last half-byte of the hash: b = 11
4 bytes at 11   c1 39 7e ea, top bit cleared: 1094287082
six digits      1094287082 mod 1000000 = 287082
The ChronoCode app with the test key in the key field, the code 287082 below the Generate button, and the countdown ring showing 1
ChronoCode, as released in December 2024, with the browser's clock fixed at 59 seconds after the start of 1970 and the test key entered. Screenshot made for this post.

The standard lists 94287082 for this moment: the same number cut to eight digits. A six-digit authenticator keeps the last six, 287082.

To check ChronoCode itself, I loaded the app with the browser’s clock fixed at that moment and typed in the key. It shows 287082, with one second left in the step.

The code changes with every step. One second later step 2 begins, and the same key gives 359152. The standard also lets a service accept the code from one step earlier, to allow for network delay, so a code typed just as it changes usually still works.

A time line of the first two minutes after midnight UTC, 1 January 1970, cut into four 30-second steps with the codes 755224, 287082, 359152 and 969429. A marker at 59 seconds falls in the second step
The test key's codes over the first two minutes of Unix time. The test time, 59 s, falls in step 1. Computed for this post and checked against the values published in RFC 4226 and RFC 6238.

What it does

  • Paste a key, get the code. Paste or type the Base32 secret and press Generate. A Paste Key button reads it from the clipboard.
  • A countdown. A ring counts down the seconds until the code changes, and the code refreshes by itself.
  • One-click copy. Copy the code to the clipboard and paste it into the login page.
  • Offline. Once loaded, it needs no internet connection.
  • Installable. On a computer or a phone, install the web app from the browser menu (Install or Add to Home Screen) and it opens like a native app.

Your key stays on your device

The design is minimal, and that is the security story:

  • Your key is never stored. ChronoCode does not save keys anywhere: not in the browser, not on a server. Close the page and the key is gone.
  • Your key is never sent. The code is computed on your device, and nothing in ChronoCode sends the key or the code anywhere. The only thing it caches is its own page, so it can open offline.
  • The extensions make no network requests at all. They ask for a single permission, to read the clipboard, for the Paste Key button.
  • The web app counts visits. Its page loads Google Analytics, which records page views as it does on many websites. ChronoCode never passes your key or your codes to it. If you would rather have no network traffic at all, use one of the extensions.

The flip side is that you need your key each time. ChronoCode is a convenient generator for keys you already keep somewhere safe, such as a password manager, not a vault that remembers them for you.

Get it