Skip to content

Password Strength

A React password field with a four step strength meter and a live rule checklist. Announces the score politely and accepts your own scorer such as zxcvbn.

src/registry/ui/password-strength.tsx/r/password-strength.json

Installation

bash
npx shadcn@latest add @minidev/password-strength

MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/password-strength.json

Usage

tsx
import { PasswordStrength } from "@/components/ui/password-strength"

export function Example() {
  return (
    <PasswordStrength />
  )
}

API reference

PasswordStrength props
PropTypeDefault
valueControlled password.string-
defaultValueInitial password when uncontrolled.string""
onChangeFires with the password on every edit.(value: string) => void-
rulesRules shown in the checklist.Rule[]DEFAULT_RULES
scoreOverride the built in 0 to 4 score.(value: string) => number-
labelVisible label above the field.string"Password"
idInput id; also prefixes the meter and checklist ids.string-
nameForm field name.string-
classNamestring-

When to use

The score is announced politely as it changes, rules are plain text for screen readers ("(met)" / "(not met)"), and nothing blocks typing. Swap in your own scorer (for example zxcvbn) with the score prop and your own policy with rules. Use it on sign-up and change-password forms; on sign-in use PasswordInput alone.

Accessibility

  • The input's aria-describedby points at the strength label and the rules list, so both are read with the field.
  • The strength label ("Weak", "Good"…) is aria-live="polite", so changes are announced as you type.
  • Each rule ends with a visually hidden "(met)" or "(not met)". The meter bars and icons are aria-hidden.
  • The input uses autoComplete="new-password" so password managers offer a generated password.

Frequently asked questions

How do I use zxcvbn or my own scoring?

Pass score, a function from the password to 0 to 4: score={(v) => zxcvbn(v).score}. The result is rounded and clamped, and the rules checklist still shows.

Does it block weak passwords?

No. Nothing stops typing or submitting. Run the same rules on submit, and check again on the server.

How is the default score worked out?

It counts the rules met, takes one off below 8 characters and adds one at 16 or more, then clamps to 1 to 4. With the default rules, "Northwind2026!" meets all four and scores 4, "Strong".

Dependencies

npm

lucide-react

Built from

Examples

Controlled with confirm

Hold the value in state to drive a confirm field and keep the submit button disabled until the two match.

Custom rules

rules replaces the checklist; each rule is a label and a test, and the built-in score counts how many pass.

Custom scorer

score overrides the meter with your own 0 to 4 number, for example from zxcvbn; the checklist still follows the rules.

All form components

Learn more