Home / Code & Data / Password & Key Generator
04.11Code & Data

Password & Key Generator

Passwords, passphrases, API keys, UUIDs and signing secrets from your browser's cryptographic random generator, with an honest entropy estimate for each. Nothing is sent anywhere.

Updated
20
Trim this to match a site's allowed characters.
5
Entropy per value
0 bits

    Where the randomness comes from

    Every value on this page is built from crypto.getRandomValues(), the browser's cryptographically secure random number generator, seeded by the operating system. It is the same source password managers and TLS use. Math.random() is never involved: it is fast and fine for games, but its output can be predicted and it must never be used for secrets.

    Nothing you generate leaves your device. There is no server call, no logging and no analytics on the values, and the page only saves your settings (length, character sets) in the address bar so you can bookmark a configuration. The values themselves are never put in the URL.

    Avoiding modulo bias

    The naive way to pick a random character is bytes[i] % alphabet.length. With a 62 character alphabet and a random byte (0 to 255), the first 8 characters come up slightly more often, because 256 is not a multiple of 62. This tool uses rejection sampling instead: it draws a 32-bit number, throws it away if it falls in the uneven tail, and only then takes the remainder. Every character is exactly equally likely.

    function randInt(n) {
      const limit = Math.floor(2 ** 32 / n) * n;
      const buf = new Uint32Array(1);
      do crypto.getRandomValues(buf); while (buf[0] >= limit);
      return buf[0] % n;
    }

    Reading the entropy number

    Entropy is length × log2(alphabet size) for random strings, and words × log2(list size) for passphrases. It assumes the attacker knows exactly how the value was made, which is the honest way to measure. Rough guidance:

    • Under 50 bits: weak for anything that can be attacked offline.
    • 60 to 80 bits: a strong user password, provided the site stores it with bcrypt, scrypt or Argon2.
    • 128 bits and up: API keys, session tokens, password reset links and anything a machine checks millions of times per second.
    • 256 bits: HMAC signing secrets for JWTs (HS256) and encryption keys.

    Picking the right mode

    Password is for accounts that live in a password manager. Go long (20 or more) and let the manager remember it. Passphrase is for the few secrets you must type or remember, like the manager's master password or a disk encryption key. API key mimics the prefixed format popularized by Stripe, which makes keys greppable and lets secret scanners on GitHub catch leaks. UUID v4 gives 122 random bits, ideal for public identifiers, but do not treat a UUID as a secret token by itself unless your threat model is relaxed. Secret bytes matches what you would get from openssl rand -hex 32 or openssl rand -base64 32.

    # .env
    JWT_SECRET=6f1c...e9a2   # 32 bytes, hex encoded
    SESSION_SECRET=Q2x...    # 32 bytes, base64

    Frequently asked questions

    Are the generated passwords sent or stored anywhere?

    No. Everything is generated in your browser with crypto.getRandomValues. Nothing is sent to a server, logged or saved, and generated values are never written into the page URL.

    How many bits of entropy do I need?

    For a password protected by a slow hash, 60 to 80 bits is strong. For API keys, signing secrets and anything that could be attacked offline at high speed, use at least 128 bits, and 256 bits for JWT HMAC secrets.

    Is a passphrase as secure as a random password?

    It can be. Each word from this 495 word list adds about 8.95 bits, so six words give roughly 54 bits and eight give about 72. Longer passphrases are easier to type and remember than random strings of the same strength.

    What length should a JWT secret be?

    For HS256, use at least 32 random bytes (256 bits). For HS512, use 64 bytes. Encode it as hex or Base64 and store it in an environment variable, never in source control.