Passwords·28 questions

What is salt and password hashing from a developer's perspective?

Answer

Password hashing is a fundamental security requirement when designing any web applications and databases. When a user registers in the system, the application must not store their original password in plain text. Instead, a one-way mathematical function is used, which turns a text string into a unique set of characters of a fixed length. This process is called hashing, and theoretically reversing it back to the original string is impossible.

However, traditional hashing is vulnerable today to attacks using pre-computed tables of possible combinations, known as rainbow tables. To protect user data from such attacks, developers use salting. Salt is a random sequence of characters that is uniquely generated for each specific user and combined with their password before computing the hash.

As a result, two different users who set the same password will get completely different hashes in the database due to the uniqueness of the salt. To implement this protection, regular fast algorithms like MD5 or SHA-256 cannot be used, since modern GPUs are capable of brute-forcing them billions of times per second. Instead, specialized slow key derivation and hashing functions should be used.

Such recommended algorithms include Argon2, bcrypt, and PBKDF2. They intentionally slow down the hash calculation process, making brute-force attacks economically unviable for attackers. When designing a database, a developer also needs to allocate sufficient field volume to store the hash itself, algorithm parameters, and the generated salt.

The correct implementation of credential storage looks as follows.

The user enters a new password on the client side and sends it over a secure HTTPS channel.
The server application generates a cryptographically strong random salt.
The application combines the password with the salt and passes this combination into the Argon2 algorithm.
The resulting hash, along with the salt and algorithm parameters, is written to the user table.
Upon a login attempt, the server takes the saved salt, adds it to the entered password, and checks the result against the database.
Was this answer helpful?

More questions in this topic

Related questions from other topics