{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "password-strength-meter",
  "title": "Password Strength Meter",
  "description": "A create-password screen that explains strength instead of just scoring it: entropy in bits and an estimated time to crack, a five-step meter, live checks for length, variety, runs, keyboard patterns, your name or email and leaked passwords, a tip for the first problem, a passphrase generator, copy and show, and saving only once it's strong.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/password-strength-meter/password-strength-meter.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 PasswordStrengthMeterProps {\n  name?: string;\n  email?: string;\n  minLength?: number;\n  /** Extra passwords to reject, on top of the built-in list of common ones. */\n  blocklist?: string[];\n  onSubmit?: (password: string) => Promise<void> | void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.55)\", faint: \"rgba(245,244,241,0.3)\", panel: \"#0E0E0E\", border: \"rgba(255,255,255,0.1)\", field: \"rgba(255,255,255,0.03)\", fieldBorder: \"rgba(255,255,255,0.12)\", focus: \"rgba(245,244,241,0.85)\", primary: \"#F5F4F1\", onPrimary: \"#0A0A0A\", off: \"rgba(255,255,255,0.1)\", well: \"rgba(255,255,255,0.04)\", ring: \"rgba(245,244,241,0.6)\", levels: [\"#FF7A6B\", \"#FF9F5A\", \"#F5C451\", \"#7BD389\", \"#3FBF7F\"] },\n  light: { bg: \"#F4F4F1\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.55)\", faint: \"rgba(10,10,10,0.3)\", panel: \"#FFFFFF\", border: \"rgba(10,10,10,0.1)\", field: \"#FFFFFF\", fieldBorder: \"rgba(10,10,10,0.16)\", focus: \"rgba(10,10,10,0.85)\", primary: \"#0A0A0A\", onPrimary: \"#FFFFFF\", off: \"rgba(10,10,10,0.1)\", well: \"rgba(10,10,10,0.03)\", ring: \"rgba(10,10,10,0.5)\", levels: [\"#E5484D\", \"#E2711D\", \"#C99A06\", \"#3E9B4F\", \"#1F9D5C\"] },\n};\n\nconst COMMON = [\"password\", \"password1\", \"123456\", \"12345678\", \"123456789\", \"qwerty\", \"qwerty123\", \"letmein\", \"welcome\", \"iloveyou\", \"admin\", \"monkey\", \"dragon\", \"sunshine\", \"football\", \"princess\", \"abc123\", \"111111\", \"passw0rd\", \"trustno1\", \"summer2026\", \"winter2026\"];\nconst KEYBOARD = [\"qwertyuiop\", \"asdfghjkl\", \"zxcvbnm\", \"1234567890\"];\nconst WORDS = [\"copper\", \"lantern\", \"orbit\", \"maple\", \"harbor\", \"velvet\", \"summit\", \"cobalt\", \"meadow\", \"falcon\", \"ember\", \"quartz\", \"willow\", \"canyon\", \"breeze\", \"atlas\", \"pepper\", \"glacier\", \"tundra\", \"saffron\"];\nconst LABELS = [\"Too weak\", \"Weak\", \"Fair\", \"Strong\", \"Very strong\"];\n\nfunction hasSequence(pw: string) {\n  const s = pw.toLowerCase();\n  for (let i = 0; i + 2 < s.length; i++) {\n    const [a, b, c] = [s.charCodeAt(i), s.charCodeAt(i + 1), s.charCodeAt(i + 2)];\n    if ((b - a === 1 && c - b === 1) || (a - b === 1 && b - c === 1)) return true;\n  }\n  return false;\n}\nconst hasRepeat = (pw: string) => /(.)\\1\\1/.test(pw);\nconst hasKeyboard = (pw: string) => {\n  const s = pw.toLowerCase();\n  return KEYBOARD.some((row) => {\n    for (let i = 0; i + 4 <= row.length; i++) if (s.includes(row.slice(i, i + 4))) return true;\n    return false;\n  });\n};\n\nfunction analyse(pw: string, personal: string[], blocklist: string[], minLength: number) {\n  const classes = [/[a-z]/, /[A-Z]/, /\\d/, /[^A-Za-z0-9]/].filter((r) => r.test(pw)).length;\n  const pool = (/[a-z]/.test(pw) ? 26 : 0) + (/[A-Z]/.test(pw) ? 26 : 0) + (/\\d/.test(pw) ? 10 : 0) + (/[^A-Za-z0-9]/.test(pw) ? 33 : 0);\n  const lower = pw.toLowerCase();\n  const breached = !!pw && [...COMMON, ...blocklist.map((b) => b.toLowerCase())].some((c) => lower === c || (c.length >= 6 && lower.replace(/[^a-z0-9]/g, \"\").includes(c.replace(/[^a-z0-9]/g, \"\"))));\n  const personalHit = personal.some((x) => x.length >= 3 && lower.includes(x));\n  const seq = hasSequence(pw) || hasRepeat(pw);\n  const kb = hasKeyboard(pw);\n  let bits = pw.length ? pw.length * Math.log2(Math.max(pool, 1)) : 0;\n  if (seq) bits -= 12;\n  if (kb) bits -= 14;\n  if (personalHit) bits -= 16;\n  if (breached) bits = Math.min(bits, 10);\n  bits = Math.max(0, bits);\n  const score = !pw ? 0 : bits < 28 ? 0 : bits < 40 ? 1 : bits < 60 ? 2 : bits < 80 ? 3 : 4;\n  const checks = [\n    { id: \"len\", label: `At least ${minLength} characters`, ok: pw.length >= minLength, tip: `Add ${Math.max(0, minLength - pw.length)} more ${minLength - pw.length === 1 ? \"character\" : \"characters\"}. Length matters most.` },\n    { id: \"mix\", label: \"Three kinds of characters, or 20+ long\", ok: classes >= 3 || pw.length >= 20, tip: \"Mix upper and lower case letters, numbers and symbols, or make it a long phrase.\" },\n    { id: \"seq\", label: \"No runs like aaa or 1234\", ok: !!pw && !seq, tip: \"Break up repeated or sequential characters.\" },\n    { id: \"kb\", label: \"No keyboard patterns\", ok: !!pw && !kb, tip: \"Avoid rows like qwerty or asdf, they're tried first.\" },\n    { id: \"you\", label: \"Doesn't include your name or email\", ok: !!pw && !personalHit, tip: \"Leave your name and email out of it.\" },\n    { id: \"breach\", label: \"Not a known leaked password\", ok: !!pw && !breached, tip: \"This password appears in leaked password lists. Pick something new.\" },\n  ];\n  return { bits, score: breached ? 0 : score, checks, breached, personalHit };\n}\n\nfunction crackTime(bits: number) {\n  const seconds = Math.pow(2, bits) / 2 / 1e10; // offline attack, 10 billion guesses a second\n  const units: [number, string][] = [\n    [60, \"second\"],\n    [60, \"minute\"],\n    [24, \"hour\"],\n    [365, \"day\"],\n    [100, \"year\"],\n    [1e6, \"century\"],\n  ];\n  if (seconds < 1) return \"instantly\";\n  let v = seconds;\n  for (const [size, name] of units) {\n    if (v < size) {\n      const n = Math.round(v);\n      return `about ${n} ${n === 1 ? name : name === \"century\" ? \"centuries\" : `${name}s`}`;\n    }\n    v /= size;\n  }\n  return \"longer than the age of the universe\";\n}\n\nexport function PasswordStrengthMeter({ name = \"Lena Brandt\", email = \"lena@nexora.io\", minLength = 12, blocklist = [\"nexora\"], onSubmit, theme = \"dark\", className }: PasswordStrengthMeterProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [pw, setPw] = React.useState(\"\");\n  const [show, setShow] = React.useState(false);\n  const [copied, setCopied] = React.useState(false);\n  const [status, setStatus] = React.useState<\"idle\" | \"saving\" | \"done\">(\"idle\");\n  const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n\n  const personal = React.useMemo(() => [...name.toLowerCase().split(/\\s+/), email.toLowerCase().split(\"@\")[0]].filter(Boolean), [name, email]);\n  const a = analyse(pw, personal, blocklist, minLength);\n  const color = p.levels[a.score];\n  const firstFail = a.checks.find((c) => !c.ok);\n  const canSave = a.score >= 3 && !a.breached && !a.personalHit && pw.length >= minLength;\n\n  React.useEffect(() => {\n    if (!copied) return;\n    const t = setTimeout(() => setCopied(false), 1600);\n    return () => clearTimeout(t);\n  }, [copied]);\n  React.useEffect(\n    () => () => {\n      if (timer.current) clearTimeout(timer.current);\n    },\n    [],\n  );\n\n  const generate = () => {\n    const pick = () => WORDS[Math.floor(Math.random() * WORDS.length)];\n    const words = [pick(), pick(), pick()].map((w) => w[0].toUpperCase() + w.slice(1));\n    const num = 10 + Math.floor(Math.random() * 90);\n    const sym = \"!#%&*?\"[Math.floor(Math.random() * 6)];\n    setPw(`${words.join(\"-\")}-${num}${sym}`);\n    setShow(true);\n  };\n  const submit = () => {\n    if (!canSave || status !== \"idle\") return;\n    setStatus(\"saving\");\n    const done = () => setStatus(\"done\");\n    const r = onSubmit?.(pw);\n    if (r instanceof Promise) r.then(done, () => setStatus(\"idle\"));\n    else timer.current = setTimeout(done, reduce ? 0 : 800);\n  };\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.panel } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const iconBtn = cn(\"grid h-8 w-8 shrink-0 cursor-pointer place-items-center rounded-lg border-0 bg-transparent\", focus);\n\n  return (\n    <section className={cn(\"@container grid min-h-[680px] w-full place-items-center px-4 py-12\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"w-full max-w-[440px] rounded-2xl border p-6 @[480px]:p-8\" style={{ background: p.panel, borderColor: p.border }}>\n        <AnimatePresence mode=\"wait\" initial={false}>\n          {status === \"done\" ? (\n            <motion.div key=\"done\" initial={reduce ? false : { opacity: 0, scale: 0.97 }} animate={{ opacity: 1, scale: 1 }} className=\"py-6 text-center\" role=\"status\">\n              <span className=\"mx-auto grid h-14 w-14 place-items-center rounded-full\" style={{ background: `${p.levels[4]}22`, color: p.levels[4] }}>\n                <svg width=\"26\" height=\"26\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                  <path d=\"m5 12.5 4.5 4.5L19 7.5\" />\n                </svg>\n              </span>\n              <h2 className=\"m-0 mt-5 text-[22px] font-semibold tracking-[-0.02em]\">Password saved</h2>\n              <p className=\"m-0 mt-2 text-[14px] leading-relaxed\" style={{ color: p.muted }}>\n                It would take {crackTime(a.bits)} to guess. Store it in a password manager.\n              </p>\n              <button\n                type=\"button\"\n                onClick={() => {\n                  setStatus(\"idle\");\n                  setPw(\"\");\n                }}\n                className={cn(\"mt-6 h-11 w-full cursor-pointer rounded-xl border text-[14px] font-medium\", focus)}\n                style={{ borderColor: p.border, background: \"transparent\", color: p.text, ...ring }}\n              >\n                Change it again\n              </button>\n            </motion.div>\n          ) : (\n            <motion.form\n              key=\"form\"\n              initial={reduce ? false : { opacity: 0 }}\n              animate={{ opacity: 1 }}\n              exit={reduce ? undefined : { opacity: 0 }}\n              onSubmit={(e) => {\n                e.preventDefault();\n                submit();\n              }}\n            >\n              <h2 className=\"m-0 text-[22px] font-semibold tracking-[-0.02em]\">Create a password</h2>\n              <p className=\"m-0 mt-1.5 text-[14px] leading-relaxed\" style={{ color: p.muted }}>\n                For <span style={{ color: p.text }}>{email}</span>. Long and unusual beats short and complicated.\n              </p>\n\n              <input type=\"email\" value={email} readOnly autoComplete=\"username\" className=\"sr-only\" tabIndex={-1} aria-hidden=\"true\" />\n              <div className=\"mt-6 flex items-baseline justify-between\">\n                <label htmlFor={`${uid}-pw`} className=\"text-[13px] font-medium\">\n                  New password\n                </label>\n                <button type=\"button\" onClick={generate} className={cn(\"flex cursor-pointer items-center gap-1.5 rounded border-0 bg-transparent p-0 text-[12.5px] font-medium\", focus)} style={{ color: p.text, ...ring }}>\n                  <svg width=\"13\" height=\"13\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                    <rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"3\" />\n                    <path d=\"M9 9h.01M15 9h.01M12 12h.01M9 15h.01M15 15h.01\" />\n                  </svg>\n                  Suggest one\n                </button>\n              </div>\n              <div className=\"mt-1.5 flex h-11 items-center rounded-xl border pr-1 pl-3.5 focus-within:border-[var(--f)]\" style={{ borderColor: pw && a.breached ? p.levels[0] : p.fieldBorder, background: p.field, [\"--f\" as string]: p.focus }}>\n                <input id={`${uid}-pw`} type={show ? \"text\" : \"password\"} value={pw} onChange={(e) => setPw(e.target.value)} autoComplete=\"new-password\" spellCheck={false} aria-describedby={`${uid}-meter ${uid}-tip`} aria-invalid={!!pw && !canSave} className=\"h-full min-w-0 flex-1 border-0 bg-transparent font-mono text-[14px] outline-none\" style={{ color: p.text }} placeholder=\"At least 12 characters\" />\n                {pw && (\n                  <button\n                    type=\"button\"\n                    onClick={() => {\n                      navigator.clipboard?.writeText(pw).catch(() => {});\n                      setCopied(true);\n                    }}\n                    aria-label=\"Copy password\"\n                    className={iconBtn}\n                    style={{ color: copied ? p.levels[4] : p.muted, ...ring }}\n                  >\n                    {copied ? (\n                      <svg width=\"15\" height=\"15\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                        <path d=\"m5 12.5 4.5 4.5L19 7.5\" />\n                      </svg>\n                    ) : (\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                        <rect x=\"8\" y=\"8\" width=\"12\" height=\"12\" rx=\"2\" />\n                        <path d=\"M16 8V5a1 1 0 0 0-1-1H5a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h3\" />\n                      </svg>\n                    )}\n                  </button>\n                )}\n                <button type=\"button\" onClick={() => setShow((s) => !s)} aria-label={show ? \"Hide password\" : \"Show password\"} aria-pressed={show} className={iconBtn} style={{ color: p.muted, ...ring }}>\n                  <svg width=\"16\" height=\"16\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                    {show ? <path d=\"M3 3l18 18M10.6 6.1A9.6 9.6 0 0 1 12 6c5 0 8.5 4.5 9.5 6a17 17 0 0 1-2.6 3.2M6.6 6.6C4.3 8 2.9 10.2 2.5 12c1 1.5 4.5 6 9.5 6 1.6 0 3-.4 4.3-1.1M9.9 9.9a3 3 0 0 0 4.2 4.2\" /> : <path d=\"M2.5 12C3.5 10.5 7 6 12 6s8.5 4.5 9.5 6c-1 1.5-4.5 6-9.5 6s-8.5-4.5-9.5-6ZM12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6Z\" />}\n                  </svg>\n                </button>\n              </div>\n\n              {/* Meter */}\n              <div id={`${uid}-meter`} className=\"mt-4\" role=\"meter\" aria-label=\"Password strength\" aria-valuemin={0} aria-valuemax={4} aria-valuenow={pw ? a.score : 0} aria-valuetext={pw ? LABELS[a.score] : \"No password yet\"}>\n                <div className=\"flex gap-1.5\">\n                  {[0, 1, 2, 3, 4].map((i) => (\n                    <span key={i} className=\"h-1.5 flex-1 overflow-hidden rounded-full\" style={{ background: p.off }}>\n                      <motion.span className=\"block h-full rounded-full\" initial={false} animate={{ width: pw && i <= a.score ? \"100%\" : \"0%\", backgroundColor: color }} transition={{ duration: reduce ? 0 : 0.25, delay: reduce ? 0 : i * 0.03 }} />\n                    </span>\n                  ))}\n                </div>\n                <div className=\"mt-2 flex items-baseline justify-between gap-3 text-[12.5px]\">\n                  <span className=\"shrink-0 font-medium whitespace-nowrap\" style={{ color: pw ? color : p.faint }}>\n                    {pw ? LABELS[a.score] : \"Strength\"}\n                  </span>\n                  <span className=\"text-right tabular-nums\" style={{ color: p.muted }}>\n                    {pw ? `${Math.round(a.bits)} bits · cracked ${crackTime(a.bits)}` : \"Start typing to see how long it would take to crack\"}\n                  </span>\n                </div>\n              </div>\n\n              {/* Checks */}\n              <ul className=\"m-0 mt-5 grid list-none grid-cols-1 gap-2 rounded-xl p-3.5 @[420px]:grid-cols-2\" style={{ background: p.well }} aria-label=\"Password checks\">\n                {a.checks.map((c) => (\n                  <li key={c.id} className=\"flex items-start gap-2 text-[12.5px] leading-[1.35]\" style={{ color: c.ok ? p.text : p.muted }}>\n                    <span className=\"relative mt-px grid h-4 w-4 shrink-0 place-items-center\" aria-hidden=\"true\">\n                      <AnimatePresence mode=\"popLayout\" initial={false}>\n                        {c.ok ? (\n                          <motion.svg key=\"ok\" width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke={p.levels[4]} strokeWidth=\"2.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" initial={reduce ? false : { scale: 0.4, opacity: 0 }} animate={{ scale: 1, opacity: 1 }} exit={reduce ? undefined : { scale: 0.4, opacity: 0 }}>\n                            <path d=\"m5 12.5 4.5 4.5L19 7.5\" />\n                          </motion.svg>\n                        ) : (\n                          <motion.span key=\"no\" className=\"h-1.5 w-1.5 rounded-full\" style={{ background: pw && c.id === \"breach\" ? p.levels[0] : p.faint }} initial={reduce ? false : { scale: 0.4, opacity: 0 }} animate={{ scale: 1, opacity: 1 }} exit={reduce ? undefined : { scale: 0.4, opacity: 0 }} />\n                        )}\n                      </AnimatePresence>\n                    </span>\n                    <span>\n                      {c.label}\n                      <span className=\"sr-only\">{c.ok ? \", done\" : \", not yet\"}</span>\n                    </span>\n                  </li>\n                ))}\n              </ul>\n\n              <p id={`${uid}-tip`} className=\"m-0 mt-3 min-h-[20px] text-[12.5px]\" style={{ color: a.breached && pw ? p.levels[0] : p.muted }} aria-live=\"polite\">\n                {!pw ? \"Tip: three or four random words with a number make a strong, memorable password.\" : firstFail ? firstFail.tip : \"Great password. Save it in your password manager.\"}\n              </p>\n\n              <button type=\"submit\" disabled={!canSave || status === \"saving\"} className={cn(\"mt-5 flex h-11 w-full cursor-pointer items-center justify-center gap-2 rounded-xl border-0 text-[14px] font-semibold disabled:cursor-not-allowed disabled:opacity-40\", focus)} style={{ background: p.primary, color: p.onPrimary, ...ring }}>\n                {status === \"saving\" && <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                {status === \"saving\" ? \"Saving…\" : \"Set password\"}\n              </button>\n            </motion.form>\n          )}\n        </AnimatePresence>\n      </div>\n    </section>\n  );\n}\n\nexport default PasswordStrengthMeter;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}