Interview Security & DevSecOps

Why do you hash and salt passwords rather than encrypt them? [Advanced]

Answer

Passwords are hashed and salted rather than encrypted because applications should not need to recover the original password. A salt makes identical passwords produce different hashes and slows precomputed/rainbow-table attacks; adaptive hashing slows brute-force attempts.

Technical explanation

If encrypted passwords are stolen along with the key, attackers can recover every password.

A unique salt per password prevents attackers from attacking many identical hashes at once.

Use password-hashing algorithms designed to be slow and tunable, not fast general-purpose hashes alone.

Hands-on example

Hands-on: when a user registers, generate a random salt and store bcrypt/Argon2id hash plus parameters. On login, hash the submitted password with the stored parameters and compare using constant-time comparison. Never log or decrypt passwords.

Preparing for an interview?

Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.

More Security & DevSecOps interview questions

← All Security & DevSecOps questions