Description
The user model or authentication service hashes passwords using md5(password) or a similarly weak function without a unique per-user salt. MD5 is a fast hashing algorithm designed for data integrity, not password storage. Pre-computed rainbow tables can reverse most common passwords in seconds.
Steps to Reproduce
- Register a user with password
Password123.
- Access the database directly and read the stored hash.
- Paste the hash into any online MD5 reverse lookup tool.
- Observe
Password123 is recovered instantly.
Root Cause
A cryptographically weak function is used for password hashing instead of a slow, salted algorithm like bcrypt, scrypt, or Argon2.
Impact
A database breach exposes all user passwords. Even "strong" passwords are at risk because MD5 can be computed at billions of hashes per second on commodity hardware.
Proposed Fix
const bcrypt = require("bcrypt");
const SALT_ROUNDS = 12;
// On registration:
const hash = await bcrypt.hash(plainPassword, SALT_ROUNDS);
// On login:
const match = await bcrypt.compare(plainPassword, storedHash);
Migrate existing hashes by prompting users to reset their passwords.
Description
The user model or authentication service hashes passwords using
md5(password)or a similarly weak function without a unique per-user salt. MD5 is a fast hashing algorithm designed for data integrity, not password storage. Pre-computed rainbow tables can reverse most common passwords in seconds.Steps to Reproduce
Password123.Password123is recovered instantly.Root Cause
A cryptographically weak function is used for password hashing instead of a slow, salted algorithm like bcrypt, scrypt, or Argon2.
Impact
A database breach exposes all user passwords. Even "strong" passwords are at risk because MD5 can be computed at billions of hashes per second on commodity hardware.
Proposed Fix
Migrate existing hashes by prompting users to reset their passwords.