ForHosting KIT · Developer Utilities

Seeded two-factor backup code generator

This seeded two-factor backup code generator creates an exact number of unique, one-time recovery codes in the familiar four-digits, hyphen, four-digits format.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

Supply a count and a secret seed, and the same inputs always produce the same ordered set. That repeatability is useful for controlled provisioning, test fixtures, documented recovery workflows, and systems that need to reconstruct codes without storing a generated list. Generation is local computation only: it uses no network call, clock, random source, account data, or hidden state. Treat the seed and every resulting code as sensitive authentication material.

Choose the count and protect the seed

Start by choosing how many recovery codes the account or application should issue. The count must be an integer from one through one thousand; a request below one is rejected instead of silently producing an empty set. Then provide a non-empty seed. The seed is the complete source of reproducibility, so identical seed and count values produce identical codes in identical order. Use a long, high-entropy secret created and stored through your organization’s approved secret-management process. A person’s name, email address, project label, or short memorable phrase is not an appropriate production seed because another person may guess it and reconstruct the codes. Do not reuse one seed across users, environments, or services. Domain separation inside the algorithm prevents accidental overlap with unrelated derivations, but it cannot compensate for a weak or exposed seed. If you need repeatable fixtures for automated tests, clearly label and isolate test seeds so their output can never be accepted by a production authentication system. The seed is limited to 4,096 characters to keep execution bounded and predictable.

Understand the deterministic generation process

Each output position is derived independently with SHA-256 from a versioned label, the exact seed length, the seed text, the zero-based position, and a retry counter. Including the seed length makes the input framing unambiguous, while the versioned label separates this purpose from other seeded calculations. The generator reads unsigned values from the digest and uses rejection sampling before reducing them to eight decimal digits. That rejection step avoids the small distribution bias that direct modulo conversion would introduce. It formats every accepted number as two groups of four digits separated by a hyphen, preserving leading zeroes. A set tracks values already emitted; if a collision occurs, the retry counter is advanced deterministically until a new code is found. Therefore the result contains the requested number of unique codes, and rerunning the same request recreates the same collision decisions as well as the same final list. No network service, system clock, runtime random generator, persisted cache, or mutable module state can influence the answer. Changing even one seed character normally changes the entire list.

Deploy, store, and invalidate codes safely

Generation is only one part of a backup-code workflow. Your authentication service must store an approved verifier for each code, mark a code consumed after its first successful use, rate-limit attempts, and provide a deliberate revocation or regeneration action. Never log the seed or plain codes in analytics, traces, support tickets, build output, or shared chat. Deliver codes to the authenticated user through a protected session and encourage offline storage in a password manager or another secure location. Determinism makes disaster recovery and controlled provisioning easier, but it also means anyone who obtains the seed can reconstruct every code. Rotate to a new independent seed whenever exposure is suspected, when a user requests regeneration, or when policy requires invalidating the old set. Do not merely request a different count with the old seed: positions shared by both requests remain the same. The grouped digits improve transcription but provide only one hundred million possible values per code, so online defenses remain essential. The API costs $0.002 per request; the browser path uses the same pure computation.

Provision recovery codes

Create a controlled set of grouped-digit recovery codes during enrollment while keeping derivation reproducible from a protected per-user seed.

Build stable authentication tests

Generate fixed backup-code fixtures for integration tests without checking a hand-maintained list into the repository.

Reconstruct an approved code set

Recover the same ordered list during a documented incident process when the protected seed remains available but the display copy does not.

What format do the codes use?

Every code contains eight decimal digits displayed as two four-digit groups, such as 0123-4567. Leading zeroes are retained.

Will the same inputs always return the same codes?

Yes. The algorithm has no random, clock, network, or stored-state dependency, so the same count and exact seed reproduce the same ordered list.

Are duplicate codes possible in one response?

No. Collisions are detected and deterministically retried until the requested list contains unique codes.

Can I use a memorable seed?

Not for production. Use a long, high-entropy secret from an approved secret-generation and storage process because possession or guessing of the seed permits reconstruction.

What happens when the count is zero or negative?

The request fails with an invalid-input error stating that count must be at least one.

How much does an API request cost?

Each API request costs $0.002. The browser version runs the same pure algorithm locally.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/security/two-factor-backup-codes-generate

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/security/two-factor-backup-codes-generate \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"count":8,"seed":"correct-horse-battery-staple-2026"}'
{
  "count": 8,
  "seed": "correct-horse-battery-staple-2026"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "security.two_factor_backup_codes_generate",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →