Security 2026-04-28
bcrypt vs Argon2: 2026年密码哈希
选择正确的密码哈希算法并为生产调整其参数。
明文存储密码不可想象。用MD5/SHA-256几乎一样糟。
故意慢的原因
GPU农场每秒哈希数十亿SHA-256候选。bcrypt/Argon2将其限制在每美元硬件每秒数千。
bcrypt
const hash = await bcrypt.hash(password, 12);
72字节输入上限。
Argon2id
const hash = await argon2.hash(password, {
type: argon2.argon2id,
memoryCost: 2 16,
timeCost: 3
});
内存硬使GPU攻击更困难。
OWASP 2026参数
- Argon2id: m=64MB, t=3
- bcrypt: cost 12
选择
新项目 → Argon2id。