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.
Installation
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
import { PasswordStrength } from "@/components/ui/password-strength"
export function Example() {
return (
<PasswordStrength />
)
}
API reference
| Prop | Type | Default |
|---|---|---|
| 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 | - |
| className | string | - |
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-describedbypoints 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
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.