Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Password Strength Form Block for React

A master-password form with advice instead of a checklist: a four-segment meter, one sentence that names the weakest thing about what is typed, a polite confirm field and a side cell that explains the four segments.

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

Tell people what to fix instead of what they failed, with this password strength form for React with Base UI. A compact header sits over a hairline frame with a plus mark on each corner, in two cells. At the start, a Password Input for the master password of Thimblekey, a family vault, with a four-segment meter and an outline Badge naming the level, and one sentence under them that names the first thing to improve: "Add 3 more characters, or two more words". A second Password Input confirms it and says "Matches" or "Does not match yet" without scolding. At the end, a side cell lists the four levels with a small meter each and marks the one you are on, then says what holds a score back. The score comes from length, variety, a typed list of 20 common passwords, your own name taken from the email and a few repeated characters. Set master password, the only Shine Button, stays pressable: a password below Good is refused with the reason and focus goes back to the field. It's built from Field, Password Input, Badge and Guides. For vaults, accounts and any form that sets a secret.

FAQ

How is the strength worked out, and can I trust it?

It is a small rule set in a pure function, scoreOf: one segment each at 8, 12 and 16 characters, one more for three kinds of character or three words, nothing at all for a password in the typed common list (a trailing number or mark does not help), and at most one segment when it contains a word from the email or repeats four or fewer different characters. That is a rough guide, not an estimator: it cannot know that a sentence from a famous book is a bad idea. For a real product use a library such as zxcvbn on the client and, whatever it says, check the password against breached lists on your server.

Why one sentence and no checklist?

A checklist turns a password into a puzzle of rules and teaches people to add "1!" to the end. One sentence that names the weakest thing first (the common list, your own name, length, repeats, then variety) says what to do next and nothing else, and it is tied to the field with aria-describedby, so a screen reader reads it when the field is focused. The ladder in the side cell shows what each level means; nothing in it is a rule to tick off.

What happens when I press Set master password with a weak one?

Nothing is set. The button stays enabled, the field is marked invalid, the sentence under the meter gets its alert icon, focus goes to the field and the foot says "Not set: pick a stronger password." A password has to reach Good (3 of 4 segments) and match the confirm field. Disabling the button instead would hide the reason from the people who need it most, and a disabled button cannot take focus or be read on its own.

What does a screen reader hear while I type?

Not one announcement per key. The level is said once, in the foot's single polite status, after you pause for about 600 milliseconds ("Strength: Good."), and the advice and the match line are read when you move to their fields. A refusal and the result are spoken at once, and after a good set the result takes focus.

What stays local, and how do I connect it for real?

Everything: the passwords live in the block's state, nothing is hashed, stored or sent, and after a good set both fields are cleared and the foot says nothing was stored. In your app derive the vault key from the password on the device (never send it as it is), send only what your design needs from submit, and show the server's answer in the same status line. Keep autoComplete="new-password" on both fields so password managers offer to save it.

How do I connect it to react-hook-form or TanStack Form?

Keep the typed text as the form's value and scoreOf as the rule. With react-hook-form, register both fields with Controller, put the strength and the match in a resolver, and keep the meter reading watch("password"). With TanStack Form, validate password on change with scoreOf and confirm with a listener on password, and keep the advice sentence out of the validator, so it can change without an error.

  • Pro

    A change-password form that says what it ends: three password fields with a line naming what the new one still needs, boxes for the other sessions, an app password and trusted devices, and a sentence that follows them.

  • Pro

    A reset page for an HR portal with a new password and confirm field, a five-segment strength meter, and a list of requirements that each show a glyph and words, never colour alone.

  • Pro

    The sign-in pair done well: an email named for password managers, a password with a reveal button and a Caps Lock warning, one generic failure that never says which half was wrong, and a quiet band with the demo account.

  • Pro

    Change Password Dialog

    Account and security

    A password manager's account page with its change-password dialog shown open: three password fields, a live checklist of five rules with a strength meter, a match line, and an Update button that stays quiet until every rule passes.

  • Pro

    The calmest form: one page with a mark, a heading that asks one question, one field with a hidden label and one full-width button, with the answer or the one problem shown under the field.

  • Pro

    A page editor whose toolbar really formats: Bold, Italic, Bullet list and Link wrap the selection in Markdown, shortcuts work, the toolbar is one tab stop with arrow keys, and a Preview tab renders the result.