Dev.to Security 🔐 Cybersecurity 👁 0 📖 6 min read

How to Audit a Password Generator Before You Trust It – CSPRNG, Modulo Bias and k-Anonymity

Sooner or later someone on your team asks which password generator they should use. We recently tested seven free ones – Google Password Manager, Apple Passwords, Bitwarden, 1Password, LastPass, NordPass and Kriptano – f

How to Audit a Password Generator Before You Trust It – CSPRNG, Modulo Bias and k-Anonymity

How to Audit a Password Generator Before You Trust It – CSPRNG, Modulo Bias and k-Anonymity

Sooner or later someone on your team asks which password generator they should use. We recently tested seven free ones – Google Password Manager, Apple Passwords, Bitwarden, 1Password, LastPass, NordPass and Kriptano – for a best password generator comparison, and the headline result is reassuringly boring: every reputable generator produces strong passwords. The differences are in details a developer can verify in a few minutes. This post is the checklist we used, with snippets you can paste into the browser console.

It matters more than it used to. According to Google Trends, US searches for "password generator free" grew by about 350% over five years, and searches for "bitwarden password generator" by about 900%. That is a lot of people creating credentials on web pages they have never looked inside.

Best password generator and free password generator searches – Google Trends growth in the US

The five criteria

  1. Randomness – a cryptographically secure source (Web Crypto or the OS) and no bias. Non-negotiable.
  2. Privacy – generated on the device, never stored by the provider.
  3. Control – length, character sets, passphrases, PINs, look-alike filtering.
  4. Defaults – strong without touching the settings, ideally 15 to 20 characters.
  5. The next step – into a vault, or to another person without copies in email or chat.

How to choose the best password generator – five tests

The first two are the ones you can check yourself from DevTools, so that is where we start.

1. Check the randomness source

A generator is only as good as its random numbers. Math.random() is fast but not cryptographically secure – V8 implements it with xorshift128+, and its output can be predicted from enough samples. In the browser the right primitive is crypto.getRandomValues() from the Web Crypto API; on a server it is the operating system's CSPRNG (crypto.randomBytes in Node.js, the secrets module in Python).

The second trap is modulo bias. Map a random byte (0–255) onto a 75-character alphabet with byte % 75 and the first 31 characters show up slightly more often, because 256 is not a multiple of 75. Rejection sampling removes the bias:

// Unbiased password generator using the Web Crypto API
const ALPHABET =
  'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&*+-=?@^_';

function generatePassword(length = 20, alphabet = ALPHABET) {
  const n = alphabet.length;
  // Reject bytes >= limit so every character is equally likely (limit = 225 for n = 75)
  const limit = 256 - (256 % n);
  const out = [];
  while (out.length < length) {
    const bytes = crypto.getRandomValues(new Uint8Array(length * 2));
    for (const b of bytes) {
      if (b < limit && out.length < length) out.push(alphabet[b % n]);
    }
  }
  return out.join('');
}

console.log(generatePassword());

If you need "at least one digit and one symbol", regenerate until the rule is met instead of overwriting random positions with forced characters. Forced positions make the output more predictable.

When you audit someone else's generator, open DevTools, go to Sources and search the bundle for getRandomValues and Math.random. Kriptano's generator, for example, uses the Web Crypto API. Passwords are not sent to or stored on the server, and only your settings are remembered in the browser.

2. Do the entropy math

Strength comes from length and alphabet size: bits = length × log2(alphabet size).

const entropyBits = (length, alphabetSize) => length * Math.log2(alphabetSize);

entropyBits(15, 94); // ≈ 98.3 – 15 printable ASCII characters
entropyBits(20, 75); // ≈ 124.6 – output of generatePassword() above
entropyBits(6, 7776); // ≈ 77.5 – six words from a 7,776-word list

Two reference points from the comparison. NIST's current guidance (SP 800-63B) sets 15 characters as the minimum for passwords used on their own, which is exactly Google's fixed default. Apple rates its 20-character hyphenated passwords at about 71 bits, because the format trades some randomness for easy typing. Maximum lengths vary even more than defaults: Google and Apple are fixed, NordPass stops at 60 characters (default 20), and Bitwarden and Kriptano go up to 128.

Free password generator maximum length – Kriptano, Bitwarden, NordPass, Apple and Google

3. Run the offline test

The most important privacy property – the password never leaves the device – is also the easiest one to verify:

  1. Open the generator and let the page load completely.
  2. Open DevTools, switch to the Network tab and click Generate a few times. A request on every click means the password is created, and could be logged, on a server.
  3. Set the Network tab to Offline (or turn on airplane mode) and generate again. If it still works, generation is local.

Kriptano's generator passes, because it keeps working offline once the page has loaded. While you are in DevTools, look for the other red flags as well: third-party ads and trackers, no HTTPS, Math.random() in the source, a short default such as 8 characters, or a page that offers to email you the password.

4. Check breaches without sending the password

A strength meter estimates how hard a password is to guess. It cannot tell you whether that exact string already sits in a breach corpus. Have I Been Pwned's Pwned Passwords API solves this with k-anonymity: hash the password with SHA-1, send only the first five hex characters and compare the returned suffixes locally.

async function pwnedCount(password) {
  const bytes = new TextEncoder().encode(password);
  const digest = await crypto.subtle.digest('SHA-1', bytes);
  const hash = Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, '0'))
    .join('')
    .toUpperCase();

  // Only these five characters leave the browser
  const res = await fetch(`https://api.pwnedpasswords.com/range/${hash.slice(0, 5)}`);
  const lines = (await res.text()).split('\n');
  const match = lines.find((line) => line.startsWith(hash.slice(5)));
  return match ? Number(match.split(':')[1]) : 0;
}

pwnedCount('password123').then(console.log);

Kriptano's optional breach check follows the same model. Only the first five characters of the SHA-1 hash are sent, never the password, and the strength test itself runs locally.

5. How the seven compare

Generator Length Extra modes Best for
Google Password Manager 15, fixed none zero effort when signing up in Chrome
Apple Passwords 20, fixed (hyphenated groups) none iPhone, iPad and Mac users
Bitwarden 5–128 passphrase (3–20 words), username generator maximum options, open source
1Password adjustable memorable, PIN, smart password in the extension 1Password users who need PINs
LastPass adjustable easy to say, easy to read passwords read aloud or typed by hand
NordPass 8–60, default 20 the basics, done well existing customers (Norton and Avast are similar)
Kriptano 4–128, default 20 passphrase (3–20 words), PIN, pronounceable, bulk, API passwords for other people

Best password generator comparison – Kriptano, Google, Apple, Bitwarden, 1Password and LastPass

6. Decide what happens after Generate

For your own accounts the right next step is a password manager, because its built-in generator saves the password to the vault immediately. The risky case is a password that has to reach someone else – a new hire, a client, a contractor. Pasted into Slack or email, it stays in histories and backups long after anyone needs it.

A one-time link avoids those copies. In Kriptano the hand-off is one click. The generated password is encrypted in the browser with AES-256-GCM, the key sits in the URL fragment after the #, which browsers never include in HTTP requests, and the encrypted copy is deleted after the first opening. Expiry runs from 1 hour to 1 year and views from 1 to 100, depending on the plan.

Password generator in a password manager versus a generator built for sharing

Bulk generation and the API

If you provision accounts in batches, clicking a button 50 times gets old quickly. Kriptano's bulk mode creates up to 100 passwords at once with TXT or CSV download, and a free API is available on every plan (API docs).

Try it

Open the Kriptano password generator and run the offline test against it, then read the full comparison of the best free password generators for per-tool details and the FAQ. For more on how random generation works, see our article on the random password generator.

Povezane analize:

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.