The purpose of password hashing is to preserve security even when a hacker gets access to your data. Saying you store the really long numbers "outside the database" is cheating. The numbers must be accessible to the server. If a hacker compromises the server then they have access to both the hashed passwords and the really long numbers. You basically just said "hide the salt". If you can hide the salt then you can hide the passwords themselves and there is no need to hash them in the first place.
If the hacker has access to your really long numbers then your proposed system is on average equivalent to a 50× slower hashing algorithm. But a 50× slower hashing algorithm is superior because it has constant time performance whereas yours fluctuates randomly between 100× slowdown to no slowdown.
Edit: Actually, the slower hashing algorithm is even better because it can't be parallelized.
Edit: Actually, the slower hashing algorithm is even better because it can't be parallelized.
That's true when you're checking one password, but a slower hashing algorithm doesn't stop you from checking multiple passwords at once (which is something you do when cracking passwords but not when authenticating them). Still, it's something I haven't thought about, so thanks for pointing that out.
Epistemic status: confidant. I'm not a cryptographer, but no one raised strong objections and I thought about it a bunch since first thinking about it.
Everyone talking about password peppering is missing a better method to implement it[1].
whether you think peppers are good or bad, knowing this is valuable. If you think they're good, this is a better method to use them. If you think they're bad, this is a stronger version to argue against. The main point of this post isn't to endorse peppers (though I do think they're good), but to compare the common methods to an alternative one.
Terms and background, in short
Skip if you're familiar
Hash: Secure password storage doesn't store passwords, so if the database leaks, the passwords aren't revealed. Instead you use a hashing function, which takes any password, and turns it into a seemingly random (very large) number, this is your hash, and this is what you store instead of the password. Hashes are hard to reverse, and unlike encryption, hashes don't have keys to decrypt them. When the user logs in, the password is hashed again and compared to the stored hash.
Salt: A random string that is added to to the password before it's hashed, and is usually stored in plain text near the now salted hash (so each salt is connected to a user). When the user logs in the salt is again hashed with their password and compared to the stored hash. Salts prevent rainbow table attacks, and make the hashes of passwords shared by multiple users unique so each password has to be cracked individually. However, the database is leaked and an attacker targets a specific user and is willing to bruteforce their password, a salt will do nothing to stop them, and the user will have to rely on the strength of their own password.
Pepper: A pepper is a secret salt that is stored without connection to a user (e.g in a separate table in the database[2]), or not stored at all. Peppering is optional - it's not required for a secure system. If you choose to use them it should always be in addition to salts since peppering doesn't provide enough security on its own. The benefit of peppering passwords is that it makes it harder to crack individual salted-hashed passwords even in the case of a leak.
Common Approaches
There's two main approaches to peppering, both should be in addition to salting.
I think method #1 is better than method #2, but my method is better than both:
My method is a combination of the two:
Do note that I'm not saying no one has come up with this before, just that I didn't see it.
Generate and store some (say, ~100) really long numbers. When a user registers, you pick one of them at random and append it to their password (in addition to a salt) before hashing. Whenever they login you try each of the stored peppers until one works.
If these are your users and their passwords:
Then this how your database will look like:
For user1, pepper 3 was selected, so we hash and stored "406d1d689f3b6026password513c98b24377f966" (salt+password+pepper)[4].
For user2 pepper 1 was picked, so we hash and store "c009b7d01c61bd19qwertyd0f008977df53df5". Notice that no where in the database do we store which peppers are used for which users.
When user1 tries to log in, we receive the password they give and append it to their salt. We go through our peppers, and each time append them to the salted password, hash the whole thing, and compare it against the stored hash. If we find a matching hash we let the user through, if we iterated through all the peppers and didn't find a matching hash we don't let the user through.
Pros over method #1:
Pros over 2#:
This is more secure than both methods, with little downside, and barely any increased complexity - Yet I wasn't able to find any source that describes something similar.
I looked for anyone mentioning a method like it and couldn't find anything.
Many sources talk of storing the pepper "outside the database", and a previous version of this article used this phrasing as well (though did mention it's not strictly necessary). The reason that, as the rest of the article explains, conventional implementations require a secrecy assumption. Though storing it "outside the database" does make it less likely the pepper would leak if the database leaks, assuming that you can keep the pepper secret if you can't keep the passwords secret is just a bad and insecure assumption. The method I suggest still benefits from secrecy (so storing "outside the database" won't hurt), but doesn't require it.
I used SHA224 for the hash, just as an example. It's not a good hashing algorithm for passwords.
This likely isn't exactly the right way to hash the three values together, but that doesn't change the core of the method.