Free online courseInteractive · No sign-up · Works offline once loaded
Hashing & password security
Why a hash can’t be decrypted, how attackers still crack millions of passwords, and how salt, bcrypt and Argon2 stop them. With live demos that run in your browser.
The course as text
Everything from the lessons in 7 short chapters, to read or to look something up later.
What a hash is
A hash function turns any input into a short, fixed-length value called a hash or digest. The same input always gives the same hash. The word hello has the MD5 hash 5d41402abc4b2a76b9719d911017c592 and the SHA-256 hash 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824, on every computer, in every programming language. MD5 always gives 32 hex characters (128 bits), SHA-256 always 64 (256 bits), no matter if you hash one letter or a whole film.
Good hash functions have an avalanche effect: change one character and about half of the output bits flip. The new hash looks completely unrelated to the old one, so you can't tell from two hashes how similar their inputs were.
Because the output has a fixed length but the input can be anything, many inputs must share each hash. Such a pair is called a collision. For a good hash it is still practically impossible to find one: SHA-256 has 2256 possible values. For MD5 (2004) and SHA-1 (2017) researchers have built collisions on purpose, so they are no longer safe where an attacker could swap data.
Hashing is not encryption and not encoding. Base64 is an encoding: anyone can turn it back. Encryption, like AES, can be reversed with the right key. A hash has no key and no way back. More in the glossary: hashing vs encryption.
Why you can’t decrypt a hash
A hash can't be decrypted, because it doesn't contain the input. It is a short summary, and most of the information is thrown away on purpose. Our toy hash in the lessons adds up the letters of a word and keeps the last two digits. From the result 24 you can't tell if the word was “cat” or one of thousands of others. Real hash functions work on bits, with far more mixing and 2256 possible results instead of 100, but the principle is the same.
So how do websites that promise “MD5 decrypt” work? They hashed huge lists of known passwords and words in advance and look your hash up in that table. If the original was on their list, they find it. If it wasn't, they can't. Our MD5 password check does the same in your browser with about 11,781 common passwords.
The other way is guessing: hash every candidate and compare. Because MD5 and SHA-256 are built to be fast, this is very quick. One gaming graphics card (an Nvidia RTX 4090) computes about 164 billion MD5 hashes per second, according to hashcat benchmarks. Every password of 8 lowercase letters is tried in about 1 second. Every 8-character password using any keyboard character takes about 11 hours.
So the honest answer to “can I decrypt this hash?” is: no, but you can check whether it is the hash of a known or weak password. If you forgot your own password, use the “forgot password” link of the service. If you are a developer, you never need to decrypt: hash what the user types and compare. More in the glossary: Can you decrypt a hash?
Passwords in a database
A website should never store your password itself. If the database leaks, every account is open, and because people reuse passwords, many other accounts too. Instead the site stores a hash. When you log in, it hashes what you typed and compares the result with the stored hash. If they match, the password was right. The site never needs to know your password.
A plain, unsalted hash is not enough. Everyone with the same password gets the same hash, so an attacker sees at once which passwords are common, and one lookup table cracks all of them. That is what happened to LinkedIn: in 2012 attackers stole about 117 million unsalted SHA-1 password hashes, and a large share was cracked quickly.
A salt fixes this. It is a random value, different for every user, that is mixed into the password before hashing and stored next to the hash. Same password, different hashes. Tables built in advance become useless, and the attacker has to guess for each user separately. The salt is not secret. It doesn't make a weak password strong; it only stops the shortcuts.
The bigger problem remains speed. SHA-256 is designed to be fast. In the race on this page, SHA-256 is many thousands of times faster than bcrypt. For files that's great. For passwords it means billions of guesses per second.
Password hashing done right
Password hashing functions are slow on purpose, and you can choose how slow. bcrypt (1999) has a cost factor: each step up doubles the work. Cost 12 means 212 rounds of its expensive key setup. Since PHP 8.4, password_hash() uses cost 12 by default. A bcrypt hash such as $2a$12$Ax/Tcn9C4O2xUF0gv8uPLeYDbEv/SW1MT9ri8zua9hcD4Cwf8c/kO contains everything needed to check a password later: the version, the cost, the 22-character salt and the 31-character hash. You store this one string.
Graphics cards are fast because they run thousands of small cores at once. scrypt and Argon2 are also memory-hard: every guess needs a lot of memory. With Argon2id at 19 MiB per guess, the 24 GB of an RTX 4090 hold only about 1,200 guesses at a time, although the card has 16,384 cores. Argon2 won the Password Hashing Competition in 2015 and is standardised as RFC 9106.
The OWASP Password Storage Cheat Sheet recommends, in this order: Argon2id with at least 19 MiB of memory, 2 iterations and 1 degree of parallelism; scrypt with N = 217, r = 8, p = 1; bcrypt with a cost of at least 10 for older systems; and PBKDF2-HMAC-SHA256 with 600,000 iterations where FIPS-140 compliance is needed. Use your language's ready-made functions, for example password_hash() and password_verify() in PHP. They create the salt for you.
Common mistakes: hashing twice with MD5, building your own sha256(salt + password), encrypting passwords instead of hashing them, limiting the length to a few characters, and forgetting that bcrypt only uses the first 72 bytes of a password.
HMAC: a hash with a key
A plain hash proves that data hasn't changed by accident. It doesn't protect against an attacker, because anyone can compute a new hash for changed data. If a message “Pay 10 EUR to Alice” is sent together with its SHA-256 hash, an attacker can change it to “Pay 1000 EUR to Mallory” and simply send the new SHA-256 along.
An HMAC (hash-based message authentication code, RFC 2104 from 1997) mixes a secret key into the hash. Only someone who knows the key can make a valid tag. The receiver recomputes the HMAC with the same key and compares. HMAC hashes twice: first the key combined with the inner padding and the message, then the key combined with the outer padding and that inner result.
Why not simply sha256(key + message)? SHA-256, SHA-1 and MD5 are open to a length-extension attack: from the hash of key + message, an attacker can compute a valid hash for a longer message without knowing the key. HMAC's double structure prevents this.
You meet HMAC in webhooks (GitHub signs every delivery in the X-Hub-Signature-256 header with HMAC-SHA256), in JSON Web Tokens with HS256, in API request signing and in the six-digit codes of authenticator apps (TOTP, RFC 6238). An HMAC can't be decrypted either. But a short or guessable key can be guessed, so use at least 32 random bytes, and compare tags with a constant-time function.
Your own passwords
How long a password survives depends on two things: how it was chosen, and how the website stores it. For a randomly chosen password, every extra character multiplies the work. Length beats symbols: P@ssw0rd! looks complex, but it is a common word with predictable swaps, and cracking tools try exactly those first. Four or five random words are long, easy to type and hard to guess. Pick them yourself at random: famous examples from comics and articles are on every cracking list.
The US standard NIST SP 800-63B-4 (2025) asks websites for at least 15 characters when a password is the only login factor, to allow at least 64, not to force mixes of character types, and to check new passwords against lists of breached passwords.
Have I Been Pwned offers such a check without learning your password. Your browser computes the SHA-1 hash of the password and sends only the first 5 hex characters. The service returns all known leaked hashes that start with them, often several hundred, and your browser compares the rest. This model is called k-anonymity. This course sends nothing; it only shows you what would be sent.
The habits that matter most: a password manager with a different password for every site, a long passphrase for the manager itself, and a second factor or a passkey wherever it is offered.
Final check
That's the whole course. To try the ideas on real values, every hash page has a password check, a comparison field and an avalanche demo, for example MD5, SHA-256 and SHA-1. To find out what kind of hash you have, use Identify.
Words you will meet
- Argon2id
- A memory-hard password hash, winner of the Password Hashing Competition 2015. OWASP’s first choice.
- Avalanche effect
- One changed input bit flips about half of the output bits.
- bcrypt
- A slow password hash from 1999 with a cost factor and a built-in salt.
- Brute force
- Trying every possible password until one matches.
- Collision
- Two different inputs with the same hash.
- Cost factor
- How much work a password hash does. In bcrypt each +1 doubles it.
- Digest
- Another word for the output of a hash function.
- HMAC
- A hash with a secret key. Proves who made a message and that it wasn’t changed.
- k-anonymity
- Sending only a short prefix of a hash, so the service can’t tell what you looked up.
- Length extension
- An attack on sha256(key + message) that HMAC prevents.
- Lookup table
- Hashes of known words, computed in advance and searched by hash.
- Memory-hard
- Needs a lot of memory per guess, which slows down graphics cards.
- Pepper
- A secret value added to all passwords and kept outside the database. Optional, on top of salt.
- Salt
- A random value per password, stored next to the hash. Makes equal passwords hash differently.