Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Security Questions Login Block for React

A sign-in step with three security questions where any two correct answers sign in: hints on demand, answers compared without capitals, accents or extra spaces, three attempts, and a locked state with a way out.

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

Ask what only the account's owner knows, and be honest about what happens when they can't answer, with this security questions login block for React with Base UI. It's the last-resort step of a Rootkin sign-in, a genealogy site: the page's side rails run the full height and one band crosses the screen in two columns. At the start, three questions, each with its own Input and a "Show hint" button that opens a typed hint in its own line; any two correct answers sign in. At the end, an attempts panel: three dots that empty as attempts are used, a word for what remains ("3 attempts left"), and a Collapsible with the demo's answers. A press that doesn't get two correct answers uses one attempt and clears the fields; the third miss locks the form ("Try again later") with a way out. On phones the panel sits under the form. It's built from Input, Collapsible, Field, Button, Shine Button and Guides, with a CSS entrance only. For recovery paths where a second factor isn't available.

FAQ

What stays in the page, and what are the demo answers?

Everything. The answers on file are Biscuit, Maple Street and Hollis, listed in the Collapsible beside the attempts; anything you type lives only in the page's state, is cleared when an attempt misses, and is never saved, sent or offered back by the browser (the fields turn autofill off). In a product, store each answer the way you store a password, as a salted hash of the normalised text, and check it on the server.

Are security questions a good idea?

Only as a last resort. Many answers can be guessed or found on social media, and the same answer is often reused across sites. If you use them, let people write their own questions, treat the answers as passwords, count attempts on the server, and never make them the only way in. This block shows the mechanics (matching, counting and locking) rather than endorsing the pattern.

How are answers compared?

After removing accents, capital letters and spaces at the ends or doubled inside, so " maple STREET " and "Hóllis" both match. The page doesn't say which answer was wrong, only that fewer than two matched, so it can't be used to test one answer at a time. Pressing with fewer than two answers filled is named ("Answer at least 2 of the 3 questions.") and costs nothing.

How do the attempts and the lock work?

There are three. Each press that doesn't get two correct answers uses one, shown by the dots and the words beside them; the third miss swaps the questions for "Try again later", which says when the form opens again as a fixed time (14:30 UTC), not a ticking clock, and offers a link to reset by email. "Reset the demo" gives the three attempts back so the block can be run again. A real lock belongs on the server, per account.

How do the hints work?

Show hint, at the end of each question's label, opens a typed hint under that field and turns into Hide hint; its state is exposed to assistive technology and the hint's line is always there, empty until opened, so nothing moves. Hints are the demo's own and say very little: a hint that gives the answer away defeats the question.

What changes on a phone?

The two columns stack: the questions and the button first, so the main action is on the first screen, and the attempts panel under them. The "attempts left" message is also written under the button when a press misses, so it is seen where the press happened.

  • Pro

    A recovery step for a casual game that shows the address on file masked and asks for the full address before it sends a code, then takes the six-digit code, with a helpdesk note for anyone without access.

  • Pro

    A verification step that asks where the code should go (text message, email or authenticator app), swaps to the code field once it is sent, and counts a limit of three codes an hour down with every send.

  • 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.

  • Pro

    Forgot Password Login

    Recovery and reset

    A forgot-password page for a school learning platform that never says whether an account exists, offers the right mail domain when one is a letter off, and resends the link on a 30-second wait.

  • Pro

    A split sign-in step for an investing app: a six-digit code field beside a demo authenticator whose code and draining ring change every 30 seconds, where the current code and the one before it both sign in.

  • Pro

    Account Locked Login

    Recovery and reset

    A locked-account page for a point-of-sale system that draws the lockout ladder, marks the rung the account is on with a fixed unlock time, and offers an unlock link by email or a password reset.