Back to cheatsheets
Passwords
Password Strength Checking
Score password strength with real entropy calculations and crack-time estimates per NIST SP 800-63B.
What you'll learn
- Honest strength score
- Crack-time estimate
- Pattern detection (NIST)
How to use these snippets
- Click the Copy button next to any snippet to copy it to your clipboard.
- Paste the code into your project, IDE, or terminal.
- Replace placeholder values (like
example.comoryour-secret) with your actual data. - Review the code comments for important security notes and caveats.
- Try the interactive related tool to see the concept in action.
Code Snippets
Copy-paste code snippets
3 ready-to-use snippets for password strength checking. Click copy and paste into your project.
Honest strength score
function scorePassword(pw) {
let charset = 0;
if (/[a-z]/.test(pw)) charset += 26;
if (/[A-Z]/.test(pw)) charset += 26;
if (/[0-9]/.test(pw)) charset += 10;
if (/[^a-zA-Z0-9]/.test(pw)) charset += 32;
const entropy = Math.log2(charset) * pw.length;
return Math.min(100, Math.round(entropy / 1.28));
}
Crack-time estimate
function crackTime(entropy, rate = 1e10) {
const guesses = Math.pow(2, entropy) / 2;
const sec = guesses / rate;
if (sec < 1) return 'instant';
if (sec < 31536000) return `${Math.round(sec)}s`;
return `${Math.round(sec / 31536000).toLocaleString()} years`;
}
Pattern detection (NIST)
function detectPatterns(pw) {
const issues = [];
if (/(.)\1{2,}/.test(pw)) issues.push('Repeated characters');
if (/(?:0123|1234|2345|3456|4567|5678|6789|abcd|qwerty)/i.test(pw))
issues.push('Sequential characters');
if (pw.toLowerCase().includes('password'))
issues.push('Contains "password"');
if (/^[0-9]+/.test(pw)) issues.push('Starts with number');
return issues;
}
Tool
Related ShieldX tool
Try this concept hands-on with the interactive tool.
100% Free · No signup · No cost
Generate something unguessable right now
148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.
Part of the Toolly ecosystem · secure.toolly.site