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.
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 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.
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
- Web app: kmmukut.github.io/ChronoCode, ready to use or install.
- Firefox: ChronoCode on Firefox Add-ons.
- Chrome, Edge, Brave and other Chromium browsers: ChronoCode on the Chrome Web Store.
- Source code: GitHub, under the MIT license. Contributions are welcome.