How do you secure user passwords?
- Always hash passwords before storing (never store plaintext).
- Use strong, slow hashing algorithms like bcrypt, argon2, or scrypt.
- Add a salt to each password (bcrypt does this automatically).
- Use libraries like bcrypt:
const bcrypt = require('bcrypt');
const hash = await bcrypt.hash(password, 10);
- When verifying:
const match = await bcrypt.compare(inputPassword, storedHash);
Database Integration