Skip to content

Password strength

Show how strong a new password is while it is typed.

PasswordStrength meterValidation
npx shadcn@latest add @silicon-ui/password-strength

Installation

With the shadcn CLI

npx shadcn@latest add @silicon-ui/password-strength

Manually

  1. Install the dependencies

    npm install motion
  2. Copy these files into your project

    • components/silicon-ui/password-strength/password-strength.tsx
    • components/silicon-ui/password-strength/password-strength.module.css
  3. Add the foundation, once per app, for the design and motion tokens

    npx shadcn@latest add @silicon-ui/silicon-foundation

Usage

usage.tsx
import { PasswordStrength } from "@/components/silicon-ui/password-strength/password-strength";

API reference

PropTypeDefault
label*string—
valuestring—
defaultValuestring""
onValueChange(value: string, strength: PasswordStrengthResult) => void—
rules

Rules to check. Strength is the share of rules met, spread over four steps.

PasswordRule[]defaultPasswordRules
error

Error copy tied to the field. The field shakes once each time a new error appears.

string—
revealedboolean—
onRevealedChange(revealed: boolean) => void—
messages

Translated or reworded copy. Every string has an English default; see PasswordStrengthMessages.

PasswordStrengthMessagesInput—
shortLength

Below this many characters the meter holds at its first step and reads "Too short". Defaults to 8.

number—
countCharacters

How characters are counted for shortLength. Defaults to code points, so an emoji counts once; pass `password => password.length` to count UTF-16 units like a server might.

(password: string) => number—

Also accepts the props of InputHTMLAttributes<HTMLInputElement>, except type, value, defaultValue, children.

Dependencies

npm
motion
Registry
silicon-motion-tokens