{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "change-password-settings-card",
  "title": "Change Password Settings Card",
  "description": "A change-password card for account settings: current password with a forgot link, a new password with a four-step strength meter, a live requirements checklist, breach and reuse warnings, a confirm field that says when it matches, show/hide toggles, an option to sign out other devices, and a saving → updated state.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/change-password-settings-card/change-password-settings-card.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface ChangePasswordValue {\n  current: string;\n  next: string;\n  signOutOthers: boolean;\n}\n\nexport interface ChangePasswordSettingsCardProps {\n  lastChanged?: string;\n  /** Return a Promise; reject with an Error whose message is shown under \"Current password\". */\n  onSubmit?: (value: ChangePasswordValue) => void | Promise<void>;\n  onForgot?: () => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", faint: \"rgba(245,244,241,0.36)\", card: \"#121212\", well: \"rgba(255,255,255,0.035)\", border: \"rgba(255,255,255,0.09)\", input: \"#0D0D0D\", track: \"rgba(255,255,255,0.1)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", green: \"#4ADE80\", amber: \"#FBBF24\", orange: \"#FB923C\", red: \"#F87171\", ring: \"rgba(245,244,241,0.6)\" },\n  light: { bg: \"#FAFAF8\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", faint: \"rgba(10,10,10,0.42)\", card: \"#FFFFFF\", well: \"rgba(10,10,10,0.03)\", border: \"rgba(10,10,10,0.1)\", input: \"#FAFAF8\", track: \"rgba(10,10,10,0.1)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", green: \"#15803D\", amber: \"#B45309\", orange: \"#C2410C\", red: \"#DC2626\", ring: \"rgba(10,10,10,0.5)\" },\n};\nconst BREACHED = [\"password\", \"password1\", \"password123\", \"qwerty123\", \"12345678\", \"iloveyou\", \"welcome1\", \"letmein1\"];\nconst RULES = [\n  { id: \"len\", label: \"At least 12 characters\", test: (s: string) => s.length >= 12 },\n  { id: \"case\", label: \"Upper and lower case letters\", test: (s: string) => /[a-z]/.test(s) && /[A-Z]/.test(s) },\n  { id: \"num\", label: \"A number or symbol\", test: (s: string) => /[\\d\\W_]/.test(s) },\n];\n\nfunction strength(s: string) {\n  if (!s) return 0;\n  let n = 0;\n  if (s.length >= 8) n++;\n  if (s.length >= 12) n++;\n  if (/[a-z]/.test(s) && /[A-Z]/.test(s)) n++;\n  if (/\\d/.test(s)) n++;\n  if (/[^\\w\\s]/.test(s)) n++;\n  if (s.length >= 16) n++;\n  return Math.min(4, Math.max(1, Math.round((n / 6) * 4)));\n}\n\nfunction Eye({ open }: { open: boolean }) {\n  return (\n    <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <path d=\"M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7S2 12 2 12Z\" />\n      <circle cx=\"12\" cy=\"12\" r=\"3\" />\n      {!open && <path d=\"M3 3l18 18\" />}\n    </svg>\n  );\n}\n\nexport function ChangePasswordSettingsCard({ lastChanged = \"Changed 3 months ago\", onSubmit, onForgot, theme = \"dark\", className }: ChangePasswordSettingsCardProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [current, setCurrent] = React.useState(\"\");\n  const [next, setNext] = React.useState(\"\");\n  const [confirm, setConfirm] = React.useState(\"\");\n  const [show, setShow] = React.useState({ current: false, next: false, confirm: false });\n  const [signOutOthers, setSignOutOthers] = React.useState(true);\n  const [status, setStatus] = React.useState<\"idle\" | \"saving\" | \"done\">(\"idle\");\n  const [error, setError] = React.useState<string | null>(null);\n  const [touched, setTouched] = React.useState(false);\n  const [changed, setChanged] = React.useState(lastChanged);\n  const currentRef = React.useRef<HTMLInputElement>(null);\n\n  const score = strength(next);\n  const passed = RULES.map((r) => r.test(next));\n  const breached = BREACHED.includes(next.toLowerCase());\n  const reused = !!next && next === current;\n  const matches = !!confirm && confirm === next;\n  const valid = !!current && passed.every(Boolean) && !breached && !reused && matches;\n  const levels = [\n    { label: \"Too weak\", color: p.red },\n    { label: \"Weak\", color: p.orange },\n    { label: \"Fair\", color: p.amber },\n    { label: \"Strong\", color: p.green },\n  ];\n  const level = breached ? levels[0] : levels[Math.max(0, score - 1)];\n\n  const submit = async (e: React.FormEvent) => {\n    e.preventDefault();\n    setTouched(true);\n    if (!valid || status === \"saving\") return;\n    setError(null);\n    setStatus(\"saving\");\n    try {\n      await (onSubmit ? onSubmit({ current, next, signOutOthers }) : new Promise((r) => setTimeout(r, reduce ? 0 : 900)));\n      setStatus(\"done\");\n      setChanged(\"Changed just now\");\n      setCurrent(\"\");\n      setNext(\"\");\n      setConfirm(\"\");\n      setTouched(false);\n    } catch (err) {\n      setStatus(\"idle\");\n      setError(err instanceof Error ? err.message : \"That password isn't right\");\n      currentRef.current?.focus();\n    }\n  };\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.card } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const label = \"block text-[12.5px] font-medium\";\n  const field = (key: \"current\" | \"next\" | \"confirm\", value: string, set: (v: string) => void, opts: { invalid?: boolean; describedBy?: string; autoComplete: string; ref?: React.Ref<HTMLInputElement> }) => (\n    <div className=\"relative mt-1.5\">\n      <input\n        id={`${uid}-${key}`}\n        ref={opts.ref}\n        type={show[key] ? \"text\" : \"password\"}\n        value={value}\n        onChange={(e) => {\n          set(e.target.value);\n          if (status === \"done\") setStatus(\"idle\");\n          if (key === \"current\") setError(null);\n        }}\n        autoComplete={opts.autoComplete}\n        aria-invalid={opts.invalid || undefined}\n        aria-describedby={opts.describedBy}\n        className={cn(\"h-10 w-full rounded-lg border pr-10 pl-3 text-[13.5px] transition-colors outline-none focus-visible:ring-2\", show[key] ? \"\" : \"tracking-[0.12em]\")}\n        style={{ borderColor: opts.invalid ? p.red : p.border, background: p.input, color: p.text, ...ring }}\n      />\n      <button type=\"button\" onClick={() => setShow((s) => ({ ...s, [key]: !s[key] }))} aria-label={show[key] ? \"Hide password\" : \"Show password\"} aria-pressed={show[key]} className={cn(\"absolute top-1/2 right-1.5 grid h-7 w-7 -translate-y-1/2 cursor-pointer place-items-center rounded-md border-0 bg-transparent\", focus)} style={{ color: p.faint, ...ring }}>\n        <Eye open={show[key]} />\n      </button>\n    </div>\n  );\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"mx-auto max-w-3xl px-4 py-10 @[640px]:px-6\">\n        <form onSubmit={submit} noValidate className=\"rounded-2xl border\" style={{ background: p.card, borderColor: p.border }}>\n          <div className=\"flex flex-wrap items-start justify-between gap-3 border-b p-5\" style={{ borderColor: p.border }}>\n            <div>\n              <h2 className=\"m-0 text-[17px] font-semibold\">Password</h2>\n              <p className=\"m-0 mt-1 text-[13px]\" style={{ color: p.muted }}>\n                Use a unique password you don&apos;t use anywhere else.\n              </p>\n            </div>\n            <span className=\"flex items-center gap-1.5 rounded-full px-2.5 py-1 text-[12px]\" style={{ background: status === \"done\" ? `${p.green}1F` : p.well, color: status === \"done\" ? p.green : p.muted }} aria-live=\"polite\">\n              <svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                <rect x=\"4\" y=\"11\" width=\"16\" height=\"10\" rx=\"2\" />\n                <path d=\"M8 11V7a4 4 0 0 1 8 0v4\" />\n              </svg>\n              {changed}\n            </span>\n          </div>\n\n          <div className=\"grid grid-cols-1 gap-6 p-5 @[640px]:grid-cols-[minmax(0,1fr)_220px]\">\n            <div className=\"flex flex-col gap-4\">\n              <div>\n                <div className=\"flex items-baseline justify-between gap-3\">\n                  <label htmlFor={`${uid}-current`} className={label}>\n                    Current password\n                  </label>\n                  <button type=\"button\" onClick={onForgot} className={cn(\"cursor-pointer border-0 bg-transparent p-0 text-[12px] underline-offset-2 hover:underline\", focus)} style={{ color: p.muted, ...ring }}>\n                    Forgot it?\n                  </button>\n                </div>\n                {field(\"current\", current, setCurrent, { invalid: !!error || (touched && !current), describedBy: error ? `${uid}-cur-err` : undefined, autoComplete: \"current-password\", ref: currentRef })}\n                <AnimatePresence initial={false}>\n                  {(error || (touched && !current)) && (\n                    <motion.p key=\"err\" id={`${uid}-cur-err`} role=\"alert\" initial={reduce ? false : { opacity: 0, y: -4 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0 }} className=\"m-0 mt-1.5 text-[12px]\" style={{ color: p.red }}>\n                      {error ?? \"Enter your current password\"}\n                    </motion.p>\n                  )}\n                </AnimatePresence>\n              </div>\n\n              <div>\n                <label htmlFor={`${uid}-next`} className={label}>\n                  New password\n                </label>\n                {field(\"next\", next, setNext, { invalid: touched && (!passed.every(Boolean) || breached || reused), describedBy: `${uid}-meter ${uid}-rules`, autoComplete: \"new-password\" })}\n                <div id={`${uid}-meter`} className=\"mt-2 flex items-center gap-2.5\" aria-live=\"polite\">\n                  <div className=\"grid flex-1 grid-cols-4 gap-1\" aria-hidden=\"true\">\n                    {[1, 2, 3, 4].map((i) => (\n                      <span key={i} className=\"h-1 overflow-hidden rounded-full\" style={{ background: p.track }}>\n                        <motion.span className=\"block h-full rounded-full\" initial={false} animate={{ width: next && (breached ? i === 1 : i <= score) ? \"100%\" : \"0%\", backgroundColor: level.color }} transition={{ duration: reduce ? 0 : 0.3, delay: reduce ? 0 : (i - 1) * 0.04 }} />\n                      </span>\n                    ))}\n                  </div>\n                  <span className=\"w-16 text-right text-[12px] font-medium\" style={{ color: next ? level.color : p.faint }}>\n                    {next ? level.label : \"—\"}\n                  </span>\n                </div>\n                <AnimatePresence initial={false}>\n                  {(breached || reused) && (\n                    <motion.p key={breached ? \"b\" : \"r\"} role=\"alert\" initial={reduce ? false : { opacity: 0, y: -4 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0 }} className=\"m-0 mt-1.5 text-[12px]\" style={{ color: p.red }}>\n                      {breached ? \"This password has appeared in a data breach. Pick another.\" : \"Your new password must be different from the current one.\"}\n                    </motion.p>\n                  )}\n                </AnimatePresence>\n              </div>\n\n              <div>\n                <label htmlFor={`${uid}-confirm`} className={label}>\n                  Confirm new password\n                </label>\n                {field(\"confirm\", confirm, setConfirm, { invalid: !!confirm && !matches && confirm.length >= next.length, describedBy: `${uid}-match`, autoComplete: \"new-password\" })}\n                <p id={`${uid}-match`} className=\"m-0 mt-1.5 flex h-4 items-center gap-1.5 text-[12px]\" style={{ color: matches ? p.green : p.red }} aria-live=\"polite\">\n                  {matches ? (\n                    <>\n                      <svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"3\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                        <path d=\"m5 12.5 4.5 4.5L19 7.5\" />\n                      </svg>\n                      Passwords match\n                    </>\n                  ) : confirm && confirm.length >= next.length ? (\n                    \"Passwords don't match\"\n                  ) : null}\n                </p>\n              </div>\n            </div>\n\n            <div className=\"flex flex-col gap-4\">\n              <div className=\"rounded-xl p-4\" style={{ background: p.well }}>\n                <p className=\"m-0 text-[12px] font-medium\" style={{ color: p.muted }}>\n                  Your password needs\n                </p>\n                <ul id={`${uid}-rules`} className=\"m-0 mt-2.5 flex list-none flex-col gap-2 p-0\">\n                  {RULES.map((r, i) => (\n                    <li key={r.id} className=\"flex items-center gap-2 text-[12.5px]\" style={{ color: passed[i] ? p.text : p.faint }}>\n                      <span className=\"grid h-4 w-4 shrink-0 place-items-center rounded-full transition-colors\" style={{ background: passed[i] ? p.green : p.track, color: p.onText }}>\n                        <AnimatePresence initial={false}>\n                          {passed[i] && (\n                            <motion.svg key=\"c\" width=\"9\" height=\"9\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" initial={reduce ? false : { scale: 0 }} animate={{ scale: 1 }} exit={reduce ? undefined : { scale: 0 }} aria-hidden=\"true\">\n                              <path d=\"m5 12.5 4.5 4.5L19 7.5\" />\n                            </motion.svg>\n                          )}\n                        </AnimatePresence>\n                      </span>\n                      <span>\n                        {r.label}\n                        <span className=\"sr-only\">{passed[i] ? \" (done)\" : \" (missing)\"}</span>\n                      </span>\n                    </li>\n                  ))}\n                </ul>\n              </div>\n              <label className=\"flex cursor-pointer items-start gap-2.5 text-[12.5px]\" style={{ color: p.muted }}>\n                <input type=\"checkbox\" checked={signOutOthers} onChange={(e) => setSignOutOthers(e.target.checked)} className=\"mt-0.5 h-3.5 w-3.5 shrink-0 cursor-pointer\" style={{ accentColor: p.green }} />\n                <span>\n                  <span className=\"block font-medium\" style={{ color: p.text }}>\n                    Sign out other devices\n                  </span>\n                  Recommended if you think someone else knows your password.\n                </span>\n              </label>\n            </div>\n          </div>\n\n          <div className=\"flex flex-wrap items-center justify-end gap-2 border-t px-5 py-4\" style={{ borderColor: p.border }}>\n            <AnimatePresence>\n              {status === \"done\" && (\n                <motion.p key=\"ok\" role=\"status\" initial={reduce ? false : { opacity: 0, x: 8 }} animate={{ opacity: 1, x: 0 }} exit={reduce ? undefined : { opacity: 0 }} className=\"m-0 mr-auto text-[12.5px]\" style={{ color: p.green }}>\n                  ✓ Password updated{signOutOthers ? \" · other devices signed out\" : \"\"}\n                </motion.p>\n              )}\n            </AnimatePresence>\n            <button\n              type=\"button\"\n              onClick={() => {\n                setCurrent(\"\");\n                setNext(\"\");\n                setConfirm(\"\");\n                setTouched(false);\n                setError(null);\n              }}\n              disabled={!current && !next && !confirm}\n              className={cn(\"h-9 cursor-pointer rounded-lg border bg-transparent px-3.5 text-[13px] font-medium disabled:cursor-not-allowed disabled:opacity-40\", focus)}\n              style={{ borderColor: p.border, color: p.text, ...ring }}\n            >\n              Cancel\n            </button>\n            <button type=\"submit\" aria-disabled={!valid} className={cn(\"flex h-9 min-w-[140px] cursor-pointer items-center justify-center gap-2 rounded-lg border-0 px-3.5 text-[13px] font-medium transition-opacity\", focus, !valid && \"opacity-50\")} style={{ background: p.on, color: p.onText, ...ring }}>\n              {status === \"saving\" ? (\n                <>\n                  <motion.span className=\"h-3.5 w-3.5 rounded-full border-2 border-current border-t-transparent\" animate={reduce ? undefined : { rotate: 360 }} transition={{ repeat: Infinity, duration: 0.7, ease: \"linear\" }} aria-hidden=\"true\" />\n                  Updating…\n                </>\n              ) : (\n                \"Update password\"\n              )}\n            </button>\n          </div>\n        </form>\n      </div>\n    </section>\n  );\n}\n\nexport default ChangePasswordSettingsCard;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}