Why SHA-256 alone is unsuitable for password storage
File checksums and server-side password storage solve different problems. Password storage must also make each offline guess expensive.
In this guide
Hashing is not encryption: there is no corresponding decryption operation. Nevertheless, after a database leak an attacker can hash guesses and compare them with stolen records without passing your application’s login rate limits.
SHA’s speed becomes a disadvantage
SHA-256 is useful for integrity checks and many cryptographic applications. Its speed is undesirable for password storage. Adding a salt to SHA256(salt + password) does not make guesses sufficiently expensive. Salt and computational cost serve different purposes.
Do not invent a credential format or a loop of ordinary hashes. Use a maintained password-hashing library.
Choose a dedicated password-hashing function
OWASP prefers Argon2id for new systems, with scrypt as an alternative when unavailable. PBKDF2 serves specific compliance requirements. Bcrypt remains relevant for legacy systems but has limitations, including input length.
Use library functions for creation and verification, salt generation and parameter storage. Choose cost parameters from current guidance and measurements on the target server. Account for concurrent logins and resource limits: costly hashing must not make denial of service trivial. Online rate limiting remains necessary.
Understand salt and pepper
A salt is random and unique to each record; it need not be secret. Store the algorithm identifier and verification parameters as well, often within the library’s encoded record.
A pepper is an optional secret kept outside the password database. It can help in some breach scenarios but complicates rotation and key management. It replaces neither salt nor a suitable hashing function.
Upgrade records after successful verification
At a successful login, verify the old record first, then rehash the submitted password if parameters are outdated. You cannot recover original passwords from existing hashes to migrate the whole database. Inactive accounts need a separate reset or migration policy. Rehashing does not undo a previous leak.
Before deployment, test incorrect passwords, legacy migration, length limits and load. Never log test passwords or send them to analytics.