Password Strength
A password input with an animated strength meter and requirements checklist.
@spectrumui/password-strength
Create account
Password strength: Too weak
- At least 8 characters
- One uppercase letter
- One number
- One symbol
Type a password — the meter fills and requirements check off as you go
Login to view codeCreate a free account to access component source code
Installation
Login to view commandCreate a free account to access the install command
Usage
import { PasswordStrengthInput } from "@/components/spectrumui/password-strength"<PasswordStrengthInput onValueChange={(value) => console.log(value)} />API Reference
PasswordStrengthInput
Renders a password input with a visibility toggle, a strength meter announced via a polite live region, and a requirements checklist. Pass value to control it from outside, or defaultValue to let it manage its own state. Strength is scored against rules, an array of PasswordRule objects of the shape { label: string; test: (value: string) => boolean }. The exported DEFAULT_RULES check for at least 8 characters, one uppercase letter, one number and one symbol.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | - | Controlled value. Leave undefined for uncontrolled usage |
defaultValue | string | "" | Initial value when uncontrolled |
onValueChange | (value: string) => void | - | Fires with the next value on every keystroke |
rules | PasswordRule[] | DEFAULT_RULES | Rules scored by the meter and listed in the checklist |
showChecklist | boolean | true | Render the requirements checklist |
showMeter | boolean | true | Render the strength meter and label |
placeholder | string | "Enter password" | Placeholder of the input |
id | string | - | Id of the input element |
name | string | - | Name of the input element |
autoComplete | string | "new-password" | Autocomplete hint of the input |
disabled | boolean | false | Disables the input and the visibility toggle |
onFocus | React.FocusEventHandler<HTMLInputElement> | - | Forwarded to the input element |
onBlur | React.FocusEventHandler<HTMLInputElement> | - | Forwarded to the input element |
className | string | - | Additional classes merged onto the wrapper element |
Examples
Custom rules and meter only
Custom rules
Password strength: Too weak
- At least 8 characters
- One uppercase letter
- One number
- One symbol
- No spaces
Meter only
Password strength: Too weak
Login to view codeCreate a free account to access component source code