Password Hashing and Security: Best Practices, Salting, and Bcrypt vs SHA Explained

Published July 13, 2026

Password Storage Basics

Password storage is not the same as ordinary checksum generation. A site should never store plain-text passwords, and it should not store a fast unsalted SHA or MD5 digest as if that were enough. The goal is to store a verifier that can confirm a later login attempt while making stolen database records expensive to attack offline.

Why Hash Passwords

Hashing passwords means the application compares a transformed value rather than the original secret. During login, the submitted password is processed with the same password hashing settings and compared with the stored verifier. If a database is exposed, attackers do not immediately receive the original passwords, but the quality of the hashing design determines how hard guessing becomes.

Why NOT to Use SHA for Passwords

SHA-256 and SHA-512 are excellent general-purpose hash functions, but they are intentionally fast. Fast hashing is good for file checksums and signatures, but bad for password storage because attackers can test huge numbers of guesses per second. A production password system should use a deliberately slow, salted password hashing function instead.

Bcrypt Explanation

Bcrypt is a long-established password hashing function with a configurable cost factor. Increasing the cost makes each password guess more expensive. Bcrypt remains common because it is available in many frameworks and has a long operational history, though teams still need to choose a suitable cost and review it over time as hardware improves.

scrypt Algorithm

scrypt adds memory hardness, which means attacks require meaningful memory as well as CPU time. That makes large-scale cracking more expensive than simple fast hashes. It is a sound option when supported by your platform and configured with appropriate memory and iteration parameters.

Argon2 Algorithm

Argon2 is a modern password hashing family designed to resist GPU and specialised hardware attacks through tunable time and memory costs. Argon2id is commonly recommended for general password storage because it balances resistance to different attack styles.

Salting Passwords

A salt is a unique random value stored alongside each password verifier. It prevents identical passwords from producing identical stored values and blocks precomputed lookup tables from being reused across accounts. Salts do not need to be secret, but they do need to be unique and generated with a secure random source.

Rainbow Tables

Rainbow tables are precomputed collections of password guesses and hashes. Unique salts make those tables impractical because the attacker would need to build separate tables for each salt. This is one reason unsalted MD5 and SHA password databases are considered severely weak.

Pepper Values

A pepper is a secret value kept outside the password database, often in application configuration or a secrets manager. It can add another layer of defence if the database alone is stolen, but it is not a replacement for a strong password hashing function, unique salts, and sensible login protections.

Key Derivation Functions

Key derivation functions such as PBKDF2 are used to turn passwords into keys or verifiers with a configurable amount of work. PBKDF2 is older than Argon2 and scrypt but remains widely available, particularly in regulated or compatibility-driven environments. Configuration matters: too few iterations weakens the design.

Password Verification Process

A typical verification flow retrieves the stored salt and parameters, hashes the submitted password with the same settings, and compares the result using a timing-safe comparison. The application should not reveal whether a username exists, and repeated failed attempts should be rate limited or otherwise controlled.

Future of Password Hashing

Password hashing settings should be reviewed as hardware changes. Systems can rehash passwords after successful login when parameters need to be strengthened. For new applications, pairing strong password hashing with multi-factor authentication, passkeys, breach checks, and account monitoring gives better protection than relying on hashing alone.

← Back to Blog | Go to Tool →