PasswordStrength
SM · 950B gzip budgetVisual password strength meter with labelled feedback.
- Category
- Forms & input
- Budget
- sm, single-purpose control
- External runtime
- React / React DOM only
axe fixtureSSR rendersource scanbundle budget
Preview
Live fixturePassword strength
Strength: Weak
Try the component here. Locale-aware formatting and direction follow the selected language; example content and labels are not automatically translated. Overlay demos use interactive launchers.
Install
npx shadcn@latest add https://gear5-ui.vercel.app/r/password-strength.jsonCopies the source into your project. Pulls in 1 shared registry item: cn.
New here? Set up Tailwind and import aliases first →Source & props
Edit on GitHub ↗Prop types and inline documentation are included below. This is repository source; the installer rewrites shared imports for your project.
"use client";
import { useId, useMemo } from "react";
import { cn } from "../lib/cn";
export interface PasswordStrengthProps {
value: string;
label: string;
className?: string;
}
const LEVELS = [
{ label: "Weak", color: "bg-red-500" },
{ label: "Fair", color: "bg-orange-500" },
{ label: "Strong", color: "bg-lime-500" },
{ label: "Very strong", color: "bg-green-600" },
];
function getStrengthLevel(password: string): number {
let score = 0;
if (password.length >= 8) score++;
if (password.length >= 12) score++;
if (/[A-Z]/.test(password) && /[a-z]/.test(password)) score++;
if (/\d/.test(password)) score++;
if (/[^A-Za-z0-9]/.test(password)) score++;
if (password.length >= 16) score++;
return Math.min(Math.floor(score / 1.5), 3);
}
export function PasswordStrength({ value, label, className }: PasswordStrengthProps) {
const id = useId();
const level = useMemo(() => (value ? getStrengthLevel(value) : -1), [value]);
return (
<div className={cn("flex flex-col gap-1.5 text-start", className)}>
<span id={id} className="text-sm font-medium">
{label}
</span>
<div className="flex gap-1" role="meter" aria-labelledby={id} aria-valuemin={0} aria-valuemax={3} aria-valuenow={level >= 0 ? level : undefined}>
{LEVELS.map((l, i) => (
<span
key={i}
aria-hidden="true"
className={cn("h-2 flex-1 rounded-full transition-colors motion-reduce:transition-none", level >= 0 && i <= level ? l.color : "bg-neutral-200 dark:bg-neutral-800")}
/>
))}
</div>
<div aria-live="polite" className="text-xs text-neutral-600 dark:text-neutral-400">
{level >= 0 && <span>Strength: {LEVELS[level].label}</span>}
</div>
</div>
);
}
What CI checks
Quality contract- Bundled, minified and gzipped against its tier budget
- Audited by axe in the state previewed above
- Rendered through react-dom/server with no browser globals
- Scanned for network calls, dangerous sinks, and unguarded animation