How do passwords actually get stored?


Wynn Tee
  
23 Sep 2020

When you create an account on the internet, you enter your username and password into a form, click a submit button, and proceed from there.

But what did the account provider do with your password? Did they store it in plain text? Did they encrypt it before storing? Do they decrypt it whenever you sign in?

In this post, I will explain three principles that responsible account providers follow when storing passwords.

Scrambled

First, your password is scrambled into a sequence of bytes, called a hash, to protect it from prying eyes.

The hash cannot be unscrambled, so every time you supply a password to access your account, the hash of your supplied password is computed and compared to the hash of your original password.

Use the following widget to see what a hash of a password looks like.

  • Password hash

  • This widget runs in your browser. It does not send your data to a server.
This widget lets you to compute the hash of a passsword using the SHA-1 hash function. In practice, there are more cryptographically secure hash functions, such as SHA-256 and SHA-512.

The hash looks like a random string of characters and does not resemble the password.

True story. In 2019, Facebook discovered that the passwords for hundreds of millions of accounts were stored in plain text on internal systems and were accessible to employees. The passwords were not scrambled.

Salted

Next, your password is scrambled only after it is appended or prepended with a random sequence of bytes, called a salt, to prevent password attacks that involve scrambling potential passwords in advance.

Use the following widget to see what a hash of a password looks like with and without salt.

  • Salted password hash

  • This widget runs in your browser. It does not send your data to a server.

This widget lets you to compute the hash of a salted password using the SHA-1 hash function and an input string for salt. In practice, there are secure random number generators for generating salts.

The second hash is less secure, because an attacker would be able to deduce the password by searching for the second hash among precomputed hashes of potential passwords.

The first hash is more secure, because the attacker would not know the salt in advance, and hence, would not be able to precompute the required hashes.

True story. In 2016, LinkedIn reported that the passwords for more than 100 million accounts, stolen from a data breach in 2012, had been put up for sale on the internet. The passwords were not salted.

Slowed

Finally, your password is scrambled using an intentionally slow algorithm to mitigate password attacks that involve scrambling potential passwords by trial‑and‑error.

Use the following widget to see how long it takes to compute a hash of a password under different speed settings.

  • Slow salted password hash

  • This widget runs in your browser. It does not send your data to a server.


This widget lets you compute the hash of a salted password slowly using the PBKDF2 algorithm with preset iteration counts. In practice, there are more advanced algorithms, such as bcrypt, scrypt, and Argon2.

The third hash is the most secure of the three hashes, because given the same list of potential passwords, an attacker would spend the most time computing hashes of incorrect passwords before arriving at the third hash.

Application

Let me conclude this post with an application. Don't depend solely on your account provider to keep your password safe.

Don't depend solely on your account provider to keep your password safe.

In the event of a data breach, a slow and salted password hash cannot stop your password from being cracked. It can only delay the crack.

But the good news is you can influence the length of that delay.

If your password is short and predictable, the delay might span a couple of seconds or minutes at most.

But if your password is long and random, which is possible with the help of a password manager, the delay might extend to a point where the attack is not deemed to be worthwhile.