Skip to content

PasswordStrength

Feedback

A transparent password requirements checklist and compact completion meter.

Live requirements checklistCompact meterCustom minimum length
Open preview

Responsive viewport — resize the window to explore. Direction and density apply only to this preview. Theme applies to the docs too.

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
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.

PasswordStrength props
PropType / DefaultDescription
valuestring

Default: required

Password to check locally; never sent or stored by this component.
minLengthnumber

Default: 12

Minimum character count; clamped to a positive integer.
showRequirementsboolean

Default: true

Show the individual completion checklist below the meter.
classNamestring

Default: —

Extend the component container with theme-aware utility classes.

Build with these too