Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
The other answers are correct, but over complicate things. Suppose you have a database with 1,000,000 email addresses and password hashes, 20% of whom are idiots and have used "password123" as the...
Answer
#1: Initial revision
The other answers are correct, but over complicate things. Suppose you have a database with 1,000,000 email addresses and password hashes, 20% of whom are idiots and have used "password123" as their password. Without salts - the attacker calculates the hash of "password123" once, compares it with all the hashes, and a millisecond later knows the password of 200,000 of the users, all at once. With salts - the attacker has to calculate the hash of "password123" with EVERY SINGLE unique salt. So checking which users have used "password123" as their password just cost them a million times more processing power. The attacker having access to the salts does not "defeat the purpose of the salt": the salt doesn't attempt to defend against "The attacker targeting one and only one password, and is going to attack that until they find it, and then stop". You salt hashes to defend against "The attacker is hoping to retrieve at least some of the passwords in the database, and they don't care which ones".