# ViraStack Password (full) > `@virastack/password` (1.2.x): headless password hook for React. Show/hide, NIST-style strength, confirmation, server validation, optional Have I Been Pwned check. Zero runtime dependencies. Errors are keys, not messages. ## Install ```bash npm install @virastack/password # peers: react, react-dom (>= 18.2) ``` Docs: https://virastack.com/password/docs; Index: https://virastack.com/password/llms.txt; Repo: https://github.com/virastack/form/tree/main/packages/password ## Entry points | Import | Exports | Runs on | | --- | --- | --- | | `@virastack/password` | `useViraPassword` (alone, or `useViraPassword(form, schema)` with React Hook Form, optional peer ≥ 7.55), `mergeProps`, `composeRefs`, `EyeIcon`, `EyeOffIcon`, `getInputType`, `getButtonAriaAttributes`, `getInputAriaAttributes` | client (`"use client"`) | | `@virastack/password/strength` | `definePolicy`, `evaluate`, `normalizePassword` | client + server | | `@virastack/password/server` | `validatePassword` + the strength exports | server | | `@virastack/password/pwned` | `checkPwned` | server (recommended) | ## Critical rules for agents 1. One hook: `useViraPassword(options)` alone, `useViraPassword(form, schema)` with React Hook Form (same shape as `useViraMask(form, schema)`). There is no `useViraPasswordStrength` or `useViraPasswordConfirm`. 2. Spread `inputProps` on the input and `btnProps` on the toggle (`type="button"` is included). 3. With React Hook Form, prefer `useViraPassword(form, schema)`: one entry per field, `matchWith` and `forbidden` take field names, `rules` adds more rules, and `inputProps` include `register()`. With `useViraPassword(options)`, pass `value` from `useWatch` (reset/setValue fire no input events); `inputProps` holds attributes only (no ref, no handlers): spread it before or after `register("password", pw.rule)` or a Mask field. 4. Define the policy once in a file without `"use client"`; import it in the form and on the server. 5. Always validate again on the server with `validatePassword`. Hash `result.password` (normalized with the policy, NFKC by default). 6. Map issue keys to messages yourself. Never block paste. 7. Call `checkPwned` from the server; on `unknown`, let the user continue. 8. Mask and Password can share one `useForm`, never the same input. ## Options | Option | Default | Notes | | --- | --- | --- | | `defaultVisible` | `false` | uncontrolled | | `visible`, `onVisibleChange` | - | controlled; `onVisibleChange` also fires on automatic hiding | | `hideOnSubmit` | `true` | hide on form submit and reset | | `hideOnBlur` | `false` | hide when focus leaves the field or the tab is hidden | | `autoComplete` | `current-password` | `new-password` with `policy` or `matchWith`; `false` omits it | | `policy` | - | from `definePolicy()`; enables `strength`, `issues` | | `forbidden` | - | values the password must not be (email, name), compared as a whole | | `normalization` | `"NFKC"` | `"NFC"` for the `matchWith` comparison; follows `policy` | | `matchWith` | - | confirm field: the password to repeat | | `value` | - | current value (e.g. `useWatch`) | | `icons` | Eye / EyeOff | `{ show, hide }` | | `disabled`, `readOnly` | `false` | lock the toggle | | `id`, `inputProps`, `btnProps` | - | merged; `on*` chained, `className`/`aria-describedby` joined, refs composed; `inputProps.id` wins over `id` | Returns: `inputProps` (attributes only), `btnProps`, `isVisible`, `toggle()`, `setVisible(v)`, `capsLock`, `strength` (`StrengthResult | null`), `strengthProps` (`role="status"`, `aria-live="polite"`), `matches` (`true | false | null`), `issues` (`PasswordIssue[]`), `rule` (`{ validate }` returning the first key or `true`). Behavior: a pointer press on the toggle returns focus and the caret to the input; Enter/Space keeps focus on the button. `spellCheck`, `autoCorrect`, `autoCapitalize` are off. ## Strength ```ts // lib/password-policy.ts (no "use client") import { definePolicy } from "@virastack/password/strength" export const policy = definePolicy({ preset: "nist", blocklist: ["acme"] }) evaluate(password, policy, { forbidden: [email, name] }) // { score: 0-4, level: "weak"|"fair"|"good"|"strong", length, valid, checks, issues } ``` - `nist` (default): 15–64 characters, no composition rules (NIST SP 800-63B-4). `mfa`: 8–64, for a password used with a second factor. `legacy` (deprecated): 8–64, lowercase + uppercase + digit + symbol. Every value can be overridden: `minLength`, `maxLength`, `require`, `blockCommon`, `blockRepetitive`, `blocklist`, `minTokenLength` (default 3), `normalization` (`"NFKC"` default or `"NFC"`). - NFKC normalization by default (`normalization: "NFC"` follows NIST; switching changes the hashed value); length in code points; zero-width characters don't count; no truncation. - `forbidden` and `blocklist` compare the whole password after removing digits, symbols, leetspeak and repetition (NIST): "ali1990" fails for the name Ali, "kaliteli-sabah-kahvesi" passes. Emails split into the local part and its pieces (domain ignored), names into words; case and accents ignored. - Level: valid passwords are `fair` at the minimum, `good` from +5 characters, `strong` from +10. Character classes don't change it. - Keys: `password.tooShort`, `password.tooLong`, `password.noLowercase`, `password.noUppercase`, `password.noDigit`, `password.noSymbol`, `password.common`, `password.blocked`, `password.repetitive`, `password.containsPersonalInfo`, `password.mismatch`, `password.pwned` (server, with the `pwned` option). - Score 0–1 fails the policy, 2–4 passes. It is a heuristic, not a crack-time estimate. ## Hook with strength and confirm (React Hook Form) ```tsx import { useViraPassword } from "@virastack/password" const form = useForm({ defaultValues: { email: "", password: "", confirm: "" } }) const { password, confirm } = useViraPassword(form, { password: { policy, forbidden: ["email"] }, // field names confirm: { matchWith: "password" }, }) {/* register() is inside */}