Password Entropy, Passphrases, and Web Crypto: Why Math.random() Is Unsafe for Security
Brian De Vivar
• Tech Contributor at BrainyToolsReviewed by Brian De Vivar — software developer & computer science educator with 20+ years of experience building software and teaching networking & systems engineering.

For years, corporate login forms trained people to build passwords like Summer2026!—eight to eleven characters with a capital letter, a number, and an exclamation point at the end. Humans feel clever inventing them; modern GPU cracking rigs guess them in milliseconds because human patterns have drastically lower entropy than truly random characters.
In this guide, we break down the information-theory math behind password entropy, explain why length beats arbitrary complexity, and show why secure client-side tools like the Cryptographic Password Generator rely on the browser's Web Crypto CSPRNG rather than JavaScript's Math.random().
How Password Entropy Is Measured in Bits
Entropy ($H$) measures the unpredictability of a secret in bits—how many binary yes/no guesses an attacker would need in the worst case to exhaust the search space ($2^H$ possibilities). For a uniformly random password of length $L$ drawn from a character pool of size $N$:
$$H = L \times \log_2(N)$$
Every +1 bit of entropy doubles the number of combinations an attacker must test.
| Password Style | Pool Size ($N$) | Length ($L$) | Entropy ($H$) | Resistance to Offline GPU Cracking |
|---|---|---|---|---|
| 6-digit PIN | 10 | 6 | ~19.9 bits |
Instant (requires strict rate limiting) |
| 8-char lowercase | 26 | 8 | ~37.6 bits |
Weak (seconds on modern hardware) |
| 12-char mixed (A-Z, a-z, 0-9, symbols) | 94 | 12 | ~78.7 bits |
Strong for everyday accounts |
| 16-char mixed (A-Z, a-z, 0-9, symbols) | 94 | 16 | ~104.9 bits |
Very strong (recommended baseline for managers) |
| 20-char mixed / API secret | 94 | 20 | ~131.1 bits |
Cryptographic-grade (exceeds 128-bit security) |
| 5-word Diceware passphrase | 7,776 words | 5 words | ~64.6 bits |
Strong and human-memorizable |
| 6-word Diceware passphrase | 7,776 words | 6 words | ~77.5 bits |
Excellent for master vault passwords |
Notice the takeaway: adding four extra characters to a random password adds ~26 bits of entropy (over 67 million times harder to brute-force), whereas swapping a for @ in a dictionary word adds almost zero real entropy because cracking rulesets (hashcat leetspeak rules) test those substitutions first.
Why Math.random() Must Never Generate Passwords or Tokens
Many quick web tutorials implement a password generator using Math.random(). That is a critical security flaw:
Math.random()is a non-cryptographic PRNG: Modern JavaScript engines (V8, SpiderMonkey, JavaScriptCore) implementMath.random()with fast algorithms like xorshift128+, designed for animations and simulations—not secrecy.- State Recovery: Observing just a small sequence of consecutive outputs from xorshift128+ allows an attacker with an SMT solver (such as Z3) to reconstruct the internal 128-bit state and predict past and future outputs.
- Modulo Bias: Even when using a secure random byte generator, naively computing
byte % charset.lengthskews character probabilities unlesscharset.lengthdivides 256 evenly.
The Right Way: Web Crypto API + Rejection Sampling
Production security tools use window.crypto.getRandomValues() backed by the operating system's CSPRNG (Cryptographically Secure Pseudo-Random Number Generator) combined with rejection sampling to eliminate modulo bias:
function generateSecurePassword(length: number, charset: string): string {
const maxValidByte = Math.floor(256 / charset.length) * charset.length;
const result: string[] = [];
const buffer = new Uint8Array(length * 2);
while (result.length < length) {
window.crypto.getRandomValues(buffer);
for (let i = 0; i < buffer.length && result.length < length; i++) {
if (buffer[i] < maxValidByte) {
result.push(charset[buffer[i] % charset.length]);
}
}
}
return result.join("");
}
Online Attacks vs. Offline Cracking: Why Entropy Thresholds Differ
Not every authentication system faces the same threat model. Understanding the difference between online guessing and offline hash cracking helps you choose sensible entropy targets without making logins unusable:
| Attack Type | Where It Happens | Typical Speed | Primary Defense |
|---|---|---|---|
| Online Brute Force / Credential Stuffing | Directly against a website's login form | 1 to 100 guesses/sec (with rate limits / lockouts) |
Unique passwords per site, MFA/Passkeys, account lockout & Turnstile/rate limiting |
| Offline Fast-Hash Cracking (MD5 / SHA-1 / NTLM) | Attacker steals leaked DB hashes and runs GPUs locally | 100+ billion guesses/sec on an 8-GPU rig |
Slow memory-hard KDFs (Argon2id) + >= 75–100 bits of password entropy |
| Offline Slow-KDF Cracking (Argon2id / bcrypt) | Attacker steals properly salted Argon2id/bcrypt hashes | 1,000 to 50,000 guesses/sec on high-end GPUs |
Strong >= 65–80 bit passphrases or 16-char random passwords |
Notice why password reuse is catastrophic: even if your bank protects logins with strict rate limits and Argon2id, reusing the same password on a small forum that leaks an unsalted SHA-1 table lets attackers crack it offline in seconds and replay it against your email and banking accounts.
NIST SP 800-63B Guidance: Why Legacy Password Rules Are Obsolete
The National Institute of Standards and Technology (NIST SP 800-63B) explicitly reversed several outdated corporate password mandates that actually weakened security:
- Stop forcing periodic 90-day rotations: Mandatory expiration without evidence of compromise trains users to increment a trailing digit (
Autumn2025!→Winter2026!), making passwords trivially predictable. - Stop enforcing rigid composition rules on short strings: Requiring "1 uppercase, 1 digit, 1 symbol" on an 8-character password nudges humans into predictable templates (capital first letter, symbol last). Favor minimum length (12–16+ characters) and support spaces/Unicode passphrases up to at least 64 characters.
- Screen against breached password lists: Rejecting the top leaked passwords from public breach corpora eliminates the vast majority of real-world account takeovers.
- Allow paste in password fields: Blocking
Ctrl+Vbreaks password managers and forces users back to weak memorized passwords.
Passwords vs. Hashing: What Happens After You Sign Up?
Even a 128-bit random password can be compromised if you reuse it across websites and one site suffers a database breach. Modern backends never store your plaintext password; they run it through a slow, salted key derivation function (Argon2id, scrypt, or bcrypt) rather than a fast checksum like raw SHA-256 or MD5.
To understand how fast cryptographic digests differ from password hashing—and how to verify file checksums locally—read our companion guide on Why Cryptographic Hash Algorithms Power Security or test digests in the Hash Generator.
Practical Password Hygiene Checklist
- Generate locally, never on a server: Use the Browser Password Generator, which runs
window.crypto.getRandomValues()entirely in local memory with zero network calls. - Use 16+ characters for stored accounts: Let a password manager handle unique 16–24 character passwords for every site.
- Use a 5- to 6-word random passphrase for master secrets: For your device unlock or password-manager master key, randomly selected words beat clever human-invented phrases every time.
- Pair with MFA / Passkeys: High entropy defeats offline cracking; multi-factor authentication defeats phishing and credential stuffing.
Frequently Asked Questions (FAQ)
Are online password generators safe to use?
Only if generation happens 100% client-side using window.crypto.getRandomValues(). Never trust a password generator that sends a server request to create a password, logs generated strings, or uses Math.random(). BrainyTools' Password Generator runs entirely in local browser memory with zero network transmission.
Should I exclude ambiguous characters like O, 0, l, and 1?
If you will type the password manually (such as a WiFi key, BIOS password, or recovery code), excluding visually ambiguous characters (0/O, 1/l/I) prevents frustrating typos while barely reducing entropy: dropping 6 characters from a 62-character alphanumeric pool only reduces entropy per character from 5.95 bits to 5.81 bits—easily offset by adding one extra character.
How many bits of entropy do I need for an API secret or JWT signing key?
For symmetric HMAC-SHA256 signing secrets, webhook secrets, or encryption keys, generate at least 256 bits (32 random bytes, e.g., 64 hex characters) using a CSPRNG rather than a short human-readable password.