Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Backup Codes Account Block for React

An account's backup codes: ten one-time codes in a hairline grid with the spent ones struck through, a meter of how many are left, a real text file to download and copy, and a new set behind a password.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Give people a way back in when their authenticator is gone, with this backup codes panel for React with Base UI. A compact header holds the title and the one Shine Button: it downloads the codes as a real text file. Inside a hairline frame with a plus mark on each corner, a segmented meter says how many of the ten codes are left, and a hairline grid shows each code in monospace with the day it was used, the spent ones struck through. The last band copies the codes that still work to the clipboard with a Copy Button and opens an Alert Dialog to generate a new set: it names how many codes it will void, asks for the account password in a Password Input, and swaps in a second set when you confirm. It's built from Download Trigger, Copy Button, Alert Dialog, Password Input, Field, Button, Shine Button and Guides, with a CSS entrance only. For the two-factor page of any app, an account's security section or a vault's recovery step.

FAQ

How do I fill it with my own codes?

Edit FIRST_SET and FRESH_SETS at the top. A set has a made date and ten codes, each with the ISO day it was used (empty while it works). The meter, the count in the heading, the line under the meter and the file are all worked out from those, so nothing is typed twice. Codes are shown as nine characters with no look-alikes (no zero, o, one, l or i) so they survive being read out; use whatever your server makes. Dates are formatted in UTC, so they read the same on the server and in every time zone.

What does Download codes save, and what does Copy take?

Download codes saves a real text file made from the set on screen: the product, the day the set was made, the ten codes numbered, each spent one marked with its day, and a line telling the person to keep it safe. Copy codes puts only the codes that still work on the clipboard, one per line, so they paste straight into a password manager; it says in the status line how many it took, or that the clipboard refused (a page that isn't served over HTTPS has none). Both are the browser's own doing: nothing is uploaded.

What stays local, and how do I make Generate real?

Everything. Confirming swaps the typed set for a second one in the page, says so in the status line and voids the old codes on screen; no request is sent and no code is stored. In your app, post the password to your server in confirm, let the server check it, make the new codes with a cryptographically secure generator, store only their hashes and return the plain codes once for display. Mark a code as used on the server when it signs someone in, and send the used days back to fill used.

How does the password step work?

The alert dialog asks for the account password because a new set replaces every old code, and a stolen session shouldn't be able to do that quietly. The field is a Password Input with a show and hide button; the confirm button stays disabled until something is typed, and in this demo any password of 8 or more characters passes, which the dialog says. Focus starts in the field, Escape and Keep my codes close it without changing anything, and focus goes back to the button that opened it. The trigger is passed to AlertDialogTrigger through render, and the dialog is controlled with open and onOpenChange.

Is it accessible?

The codes are a real list named Backup codes, each in a left-to-right monospace span so a right-to-left page doesn't reorder them, and a spent code says so in text ("Used 3 Oct. It no longer works"), never only with the strikethrough. The meter is decorative: the count is written beside it as "7 of 10 left". One polite status line is present from the start and reports each copy and each new set. The buttons are named, every control is reachable with Tab, and the dialog traps focus and returns it.

How does it look on a phone?

The header button drops under the sentence, the grid keeps two codes across because nine characters fit a narrow column, and the two actions at the foot share a row with the status line above them. The alert dialog is the catalog's: a sheet stuck to the bottom of the screen.

  • Pro

    An account's two-factor methods as rows with their role, history and a Test that opens a code field in place, Make primary, a guarded Remove, and a Set up that opens a QR code, a key name or a number.

  • Pro

    An account's recovery options: four numbered ways back in, each with its state in words, a masked value, a quiet test and a one-field form to set it up, and a line that counts how many are ready.

  • Pro

    Passkeys Account

    Sign-in methods

    An account's passkeys: a ruled list of what each one is, when it was created and last used, a name you edit in place, a guarded Remove, and a dialog from the header that names a new passkey.

  • Pro

    Trusted Devices Account

    Sessions and devices

    An account's trusted devices as a table of devices against two switches, one to skip the sign-in code and one to skip the password prompt, with a sentence on what each device's choice means and a meter against the limit.

  • Pro

    Security Review Account

    Sessions and devices

    A security review in three sections, devices, recent sign-ins and sign-in methods, where each item is answered with Yes, this is mine or Remove, with a progress bar and a Finish button that waits for every answer.

  • Pro

    Backup Code Login

    Codes and approvals

    A sign-in step that takes one of eight single-use backup codes: the field adds the dash as you type, a saved sheet strikes spent codes through, and signing in offers new codes behind an alert dialog.