Most password strength checkers lie. They show a green bar for "Password1!" because it has uppercase, lowercase, digits, and symbols — but it has only ~47 bits of entropy and cracks in seconds. In this tutorial, you will build a strength checker that tells the truth.
The problem with pattern-based scoring
Traditional checkers score passwords based on character class diversity: +1 for uppercase, +1 for digits, +1 for symbols. This rewards "P@ssw0rd1!" with a high score despite it being in every cracking dictionary. NIST SP 800-63B explicitly warns against this approach.
Verifiers SHALL NOT impose other composition rules (e.g., requiring mixtures of different character types or prohibiting consecutively repeated characters) for memorized secrets.
NIST SP 800-63B, Section 5.1.1.2
Entropy: the honest metric
Entropy measures the number of guesses an attacker needs. We calculate it as H = L × log2(N) where L is password length and N is the effective charset size. The key word is effective — we must account for patterns.
function calculateEntropy(password) {
let charsetSize = 0;
if (/[a-z]/.test(password)) charsetSize += 26;
if (/[A-Z]/.test(password)) charsetSize += 26;
if (/[0-9]/.test(password)) charsetSize += 10;
if (/[^a-zA-Z0-9]/.test(password)) charsetSize += 32;
const rawEntropy = password.length * Math.log2(charsetSize);
return rawEntropy;
}
Detecting common patterns
Raw entropy overestimates strength when patterns exist. A password like "abcdefghij12" has 12 characters from a 62-char set (71 bits raw), but the alphabetical sequence and trailing digits make it far weaker. We detect and penalize:
- Sequential characters: abc, 123, qwerty
- Repeated characters: aaaa, 1111
- Common substitutions: @→a, $→s, 3→e
- Dictionary words: password, admin, love
- Keyboard walks: asdf, zxcv
const SEQUENCES = ['abcdefghijklmnopqrstuvwxyz', '0123456789', 'qwertyuiop', 'asdfghjkl', 'zxcvbnm'];
function detectPatterns(password) {
const lower = password.toLowerCase();
const penalties = [];
for (const seq of SEQUENCES) {
for (let i = 0; i <= seq.length - 3; i++) {
const slice = seq.slice(i, i + 3);
if (lower.includes(slice)) {
penalties.push({ type: 'sequence', value: slice, bits: 8 });
}
}
}
if (/(.)\1{2,}/.test(password)) {
penalties.push({ type: 'repeat', bits: 6 });
}
const normalized = lower.replace(/@/g, 'a').replace(/$/g, 's').replace(/3/g, 'e').replace(/1/g, 'i').replace(/0/g, 'o');
const COMMON_WORDS = ['password', 'admin', 'letmein', 'welcome', 'monkey', 'dragon', 'love', 'master'];
for (const word of COMMON_WORDS) {
if (normalized.includes(word)) {
penalties.push({ type: 'dictionary', word, bits: 20 });
}
}
return penalties;
}
Calculating effective entropy
function effectiveEntropy(password) {
const raw = calculateEntropy(password);
const penalties = detectPatterns(password);
const totalPenalty = penalties.reduce((sum, p) => sum + p.bits, 0);
return Math.max(0, raw - totalPenalty);
}
Translating entropy to crack-time
We estimate crack-time assuming an attacker can try 10 billion hashes per second (offline attack with GPU rigs).
function crackTime(entropyBits) {
const guesses = Math.pow(2, entropyBits);
const guessesPerSecond = 1e10;
const seconds = guesses / guessesPerSecond;
if (seconds < 1) return 'instantly';
if (seconds < 60) return Math.round(seconds) + ' seconds';
if (seconds < 3600) return Math.round(seconds / 60) + ' minutes';
if (seconds < 86400) return Math.round(seconds / 3600) + ' hours';
if (seconds < 31536000) return Math.round(seconds / 86400) + ' days';
const years = seconds / 31536000;
if (years < 1000) return Math.round(years) + ' years';
if (years < 1e6) return Math.round(years / 1000) + 'K years';
return (years / 1e9).toFixed(1) + 'B years';
}
Building the strength meter
function strengthScore(entropy) {
if (entropy < 28) return { score: 0, label: 'Very Weak', color: '#ef4444' };
if (entropy < 36) return { score: 1, label: 'Weak', color: '#f97316' };
if (entropy < 60) return { score: 2, label: 'Fair', color: '#eab308' };
if (entropy < 80) return { score: 3, label: 'Strong', color: '#22c55e' };
if (entropy < 120) return { score: 4, label: 'Very Strong', color: '#14b8a6' };
return { score: 5, label: 'Excellent', color: '#06b6d4' };
}
TipThe ShieldX Password Strength Checker implements all of this in real-time. Type a password and watch the entropy and crack-time update instantly — with zero network requests.
Try it yourself
Open the ShieldX Password Strength Checker and test "P@ssw0rd1!" vs "correct-horse-battery-staple". Notice how the passphrase scores higher despite being "simpler" by traditional rules.