Performance: Password hashing with bcrypt
MEDIUM IMPACT
This affects server response time during user authentication and registration due to CPU-intensive hashing.
const bcrypt = require('bcrypt'); async function hashPassword(password) { const saltRounds = 12; // recommended secure level return await bcrypt.hash(password, saltRounds); }
const bcrypt = require('bcrypt'); async function hashPassword(password) { const saltRounds = 4; // very low return await bcrypt.hash(password, saltRounds); }
| Pattern | CPU Load | Event Loop Blocking | Response Delay | Verdict |
|---|---|---|---|---|
| Low salt rounds (e.g., 4) | Low CPU | No blocking | Fast response | [!] OK but insecure |
| Recommended salt rounds (e.g., 12) | High CPU | No blocking if async | Moderate delay (~100ms) | [OK] Secure and performant |
| Synchronous bcrypt calls | High CPU | Blocks event loop | Delays all requests | [X] Bad for server responsiveness |