# Password Strength

A segmented strength meter, verdict, and requirements list for a password field.

Password Strength scores a password you already hold in state. The meter, verdict, and requirements list read that score from context, so they can sit in any order under the input.

```tsx
import { Field, Input, PasswordStrength } from "@zentara-co/zenos-ui";
import { useState } from "react";

function PasswordStrengthExample() {
  const [password, setPassword] = useState("");

  return (
    <Field.Root className="w-full max-w-sm">
      <Field.Label>Password</Field.Label>
      <Field.Control
        render={
          <Input
            autoComplete="new-password"
            type="password"
            value={password}
            onChange={(event) => setPassword(event.target.value)}
          />
        }
      />
      <PasswordStrength className="pt-1" value={password}>
        <PasswordStrength.Label />
        <PasswordStrength.Meter />
        <PasswordStrength.List />
      </PasswordStrength>
    </Field.Root>
  );
}
```

## Import

```tsx
import { PasswordStrength } from "@zentara-co/zenos-ui";
```

## Composition

Pass the same string to the password input and to `PasswordStrength`. The root scores `value` and the parts render the result.

```tsx
<PasswordStrength value={password}>
  <PasswordStrength.Label />
  <PasswordStrength.Meter />
  <PasswordStrength.List />
</PasswordStrength>
```

```text
PasswordStrength
├── PasswordStrength.Label
├── PasswordStrength.Meter
└── PasswordStrength.List
```

Omit `children` to render that same arrangement. The default policy asks for 8 characters, an uppercase letter, and a special character from `!@#$%^&*`.

## Requirements

`PasswordStrength.List` renders one row per rule. A met rule slides its dot up and brings a check in from below. Motion-reduction preferences show the settled icon without the slide.

## Custom policy

Replace `rules` with your own `{ id, label, test }` list. The meter stays four segments: partial matches fill one, two, or three, and the fourth fills only when every rule passes. The verdict follows those segments: Weak, Fair, Good, then Strong.

```tsx
import { Input, PasswordStrength, Stack } from "@zentara-co/zenos-ui";
import { useState } from "react";

function PasswordStrengthRulesExample() {
  const [password, setPassword] = useState("");
  const rules = [
    { id: "length", label: "At least 12 characters", test: (value: string) => value.length >= 12 },
    {
      id: "case",
      label: "Upper and lowercase letters",
      test: (value: string) => /[A-Z]/.test(value) && /[a-z]/.test(value),
    },
    { id: "number", label: "At least one number", test: (value: string) => /\d/.test(value) },
    {
      id: "symbol",
      label: "At least one symbol (!@#$…)",
      test: (value: string) => /[!@#$%^&*]/.test(value),
    },
    {
      id: "spaces",
      label: "No spaces",
      test: (value: string) => value.length > 0 && !/\s/.test(value),
    },
  ];

  return (
    <Stack className="w-full max-w-sm" gap="3">
      <Input
        aria-label="Password"
        autoComplete="new-password"
        type="password"
        value={password}
        onChange={(event) => setPassword(event.target.value)}
      />
      <PasswordStrength rules={rules} value={password}>
        <PasswordStrength.Meter />
        <PasswordStrength.Label placeholder="-" />
        <PasswordStrength.List />
      </PasswordStrength>
    </Stack>
  );
}
```

## Inside a field

Place the strength block after the control. [Field](/components/field/) keeps the label and input wiring. The meter is a separate reading, so it is not the field description.

## Anatomy

```text
PasswordStrength.Root
PasswordStrength.Label
PasswordStrength.Meter
PasswordStrength.List
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| value | string | — | Password currently held by the input. |
| rules | PasswordStrengthRule[] | passwordStrengthRules | Policy of { id, label, test }. The meter always uses four segments, whatever the rule count. |
| Label.placeholder | ReactNode | "-" | Shown before any rule is met. |
| native props | React.HTMLAttributes<HTMLElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

The meter exposes `aria-valuemin`, `aria-valuemax`, `aria-valuenow`, and `aria-valuetext`. The verdict is a polite live region, so a strength change is announced without moving focus. Each requirement includes visually hidden “Met” or “Not met” text. The dot and check are decorative.

Keep the password in the input. This component only reports how that value scores against the policy.

Source: https://zenos-ui.pages.dev/components/password-strength/