Performance: Password hashing with bcrypt
MEDIUM IMPACT
This affects server response time during user authentication and registration by adding CPU work for hashing passwords.
const bcrypt = require('bcrypt'); app.post('/signup', async (req, res) => { const password = req.body.password; const hashed = await bcrypt.hash(password, 12); // recommended salt rounds // save hashed password res.send('User created'); });
const bcrypt = require('bcrypt'); app.post('/signup', async (req, res) => { const password = req.body.password; const hashed = await bcrypt.hash(password, 4); // low salt rounds // save hashed password res.send('User created'); });
| Pattern | CPU Load | Blocking Behavior | Response Delay | Verdict |
|---|---|---|---|---|
| bcrypt with low salt rounds | Low CPU | Non-blocking (async) | Fast response | [X] Bad |
| bcrypt with recommended salt rounds | Medium CPU | Non-blocking (async) | Moderate delay | [OK] Good |
| bcrypt with recommended salt rounds (sync) | Medium CPU | Blocking | High delay | [X] Bad |
| No hashing or weak hashing | Minimal CPU | Non-blocking | Fast but insecure | [X] Bad |