密码强度评估标准:NIST 最新指南解读
密码强度评估是安全系统的重要组成部分。本文解读 NIST 最新密码指南。
NIST 密码指南(2024)
旧规则(已淘汰)
- ❌ 强制包含大小写、数字、特殊字符
- ❌ 强制 90 天更换密码
- ❌ 最小长度 8 位
新规则(推荐)
- ✅ 最小长度 8 位,推荐 12+ 位
- ✅ 不强制复杂度要求
- ✅ 不强制定期更换
- ✅ 检查常见密码黑名单
- ✅ 支持密码粘贴
密码强度计算
熵值计算
密码强度用熵值(bit)衡量:
熵值 = log2(字符集大小 ^ 密码长度)
| 密码类型 | 字符集大小 | 12位熵值 |
|---|---|---|
| 纯数字 | 10 | 40 bit |
| 小写字母 | 26 | 56 bit |
| 大小写+数字 | 62 | 71 bit |
| 全字符集 | 95 | 79 bit |
JavaScript 实现
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 += 33;
return Math.floor(password.length * Math.log2(charsetSize));
}
密码强度等级
| 熵值 | 强度 | 说明 |
|---|---|---|
| < 28 | 极弱 | 瞬间可破解 |
| 28-35 | 弱 | 几分钟可破解 |
| 36-59 | 中 | 几小时到几天 |
| 60-127 | 强 | 几年到几百年 |
| ≥ 128 | 极强 | 理论上不可破解 |
常见弱密码
const weakPasswords = [
'123456',
'password',
'12345678',
'qwerty',
'123456789',
'12345',
'1234567',
'admin',
'1234567890',
'letmein'
];
密码强度检查
function checkPasswordStrength(password) {
const checks = {
length: password.length >= 8,
hasLower: /[a-z]/.test(password),
hasUpper: /[A-Z]/.test(password),
hasNumber: /[0-9]/.test(password),
hasSpecial: /[^a-zA-Z0-9]/.test(password),
notCommon: !weakPasswords.includes(password.toLowerCase())
};
const score = Object.values(checks).filter(Boolean).length;
if (score <= 2) return '弱';
if (score <= 4) return '中';
return '强';
}
最佳实践
- 长度优先:长密码比复杂密码更安全
- 密码短语:使用多个随机单词
- 黑名单检查:检查常见密码和泄露密码
- 实时反馈:密码输入时显示强度指示器
- 教育用户:解释密码安全的重要性
总结
现代密码安全更注重长度而非复杂度。使用密码短语、密码管理器,配合双因素认证,是保护账户安全的最佳方案。