PasswordStrength
FeedbackA transparent password requirements checklist and compact completion meter.
Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.
"use client";
import { PasswordStrength } from "@/components/ui/password-strength";
import { Input } from "@dashboardpack/core/components/ui/input";
import { Label } from "@dashboardpack/core/components/ui/label";
import { useId, useState } from "react";
export default function PasswordStrengthExample() {
const [password, setPassword] = useState("");
const id = useId();
return (
<div className="w-full max-w-sm space-y-7">
<div className="space-y-3">
<Label htmlFor={id}>Try a sample password</Label>
<Input
id={id}
type="password"
autoComplete="new-password"
placeholder="Start typing to check requirements"
value={password}
onChange={(event) => setPassword(event.target.value)}
/>
<PasswordStrength value={password} />
</div>
<div className="border-t pt-5">
<p className="mb-3 text-xs font-medium text-muted-foreground">
COMPACT · CUSTOM LENGTH
</p>
<PasswordStrength
value="Example!2026"
minLength={16}
showRequirements={false}
/>
</div>
</div>
);
}Usage
Show this alongside password entry to explain the configured requirements. The four checks cover minimum length, ASCII uppercase and lowercase letters, a number, and a non-whitespace symbol. The meter counts checks passed. It does not estimate entropy, check breached passwords, or replace server validation. Use a password manager and a real policy for production authentication.
import { PasswordStrength } from "@/components/ui/password-strength";Shipped as editable source in src/components/ui/password-strength.tsx in both apps. Copy the implementation below when moving it to another project. Copy the complete example from Source code for all imports and state. Add "use client" when using hooks or event handlers. See installation and theming for project setup.
Component source
The complete implementation is included in both apps. It uses the React, Radix, Lucide, and shared-core dependencies already installed in Apex. Keep your project’s semantic theme tokens when reusing it.
src/components/ui/password-strength.tsx
"use client";
import { useId } from "react";
import { Check, Circle } from "lucide-react";
import { cn } from "@dashboardpack/core/lib/utils";
export function passwordRequirements(value: string, minLength = 12) {
return [
{
label: `At least ${minLength} characters`,
met: value.length >= minLength,
},
{
label: "Uppercase and lowercase letters",
met: /[a-z]/.test(value) && /[A-Z]/.test(value),
},
{ label: "At least one number", met: /[0-9]/.test(value) },
{ label: "At least one symbol", met: /[^a-zA-Z0-9\s]/.test(value) },
];
}
export interface PasswordStrengthProps {
value: string;
minLength?: number;
showRequirements?: boolean;
className?: string;
}
export function PasswordStrength({
value,
minLength = 12,
showRequirements = true,
className,
}: PasswordStrengthProps) {
const id = useId();
const requirements = passwordRequirements(
value,
Math.max(1, Math.floor(minLength) || 12),
);
const score = requirements.filter((item) => item.met).length;
const label = !value
? "Not entered"
: ["Very weak", "Weak", "Fair", "Good", "Meets all requirements"][score];
return (
<div className={cn("space-y-3", className)}>
<div className="flex items-center justify-between gap-3 text-xs">
<span id={id} className="font-medium">
Password requirements
</span>
<span className="text-muted-foreground">{label}</span>
</div>
<div
role="meter"
aria-labelledby={id}
aria-valuemin={0}
aria-valuemax={4}
aria-valuenow={score}
aria-valuetext={label}
className="flex gap-1.5"
>
{requirements.map((item, index) => (
<span
key={item.label}
className={cn(
"h-1.5 flex-1 rounded-full",
index >= score
? "bg-muted"
: score < 2
? "bg-destructive"
: score < 4
? "bg-primary/60"
: "bg-primary",
)}
/>
))}
</div>
{showRequirements && (
<ul className="grid gap-2 text-xs">
{requirements.map((item) => (
<li
key={item.label}
className={cn(
"flex items-center gap-2",
item.met ? "text-foreground" : "text-muted-foreground",
)}
>
{item.met ? (
<Check aria-hidden className="size-3.5 text-primary" />
) : (
<Circle aria-hidden className="size-3.5" />
)}
<span>
{item.label}
<span className="sr-only">
: {item.met ? "met" : "not met"}
</span>
</span>
</li>
))}
</ul>
)}
<p className="text-xs text-muted-foreground">
A requirements checklist, not an estimate of password security.
</p>
</div>
);
}API reference
Common props and defaults. Slot-specific props are named below; native elements also accept their standard HTML attributes. The component TypeScript definitions are the complete type reference.
| Prop | Type / Default | Description |
|---|---|---|
| value | stringDefault: required | Password to check locally; never sent or stored by this component. |
| minLength | numberDefault: 12 | Minimum character count; clamped to a positive integer. |
| showRequirements | booleanDefault: true | Show the individual completion checklist below the meter. |
| className | stringDefault: — | Extend the component container with theme-aware utility classes. |