问题
Based on my research the purpose of a salt is to defeat the use of a rainbow table. This is done because rainbow tables are only created to look up hashes of a sole password(without a salt). I am having a conflict understanding how we can't use rainbow tables in when salts are introduced. Suppose we have the following scenario:
I am a malicious hacker and I want to gain access to a rich person's bank account. I am able to gain access to the bank's database which has the salt and the hashed string in plain sight, which is a function of the user's password and salt (f(password + salt)). The salt is fsd88
. Next I get a rainbow table from some hacker on the web. Great, so I am all ready to become rich and move to Switzerland.
What I do next is I take the the hashed string and look it up on the rainbow table (according to a tutorial online this takes about an hour to do). The rainbow table look up then returns passwfsd88. Since I know the salt is fsd88. I now know what the password is! It's passw!
What is wrong with my mental model of a salt? Thanks for reading.
回答1:
The salt is added before the hash is calculated:
$password = 'secret';
$salt = 'kU832hNWQ2122093uiue';
$passwordHash = hash($password + $salt);
In this example not the hash of password 'secret'
was calculated, instead it is the hash of 'secretkU832hNWQ2122093uiue'
. Nobody will ever create a rainbowtable with such passwords, if you find a precalculated rainbow-table it would contain the hash of 'secret'
.
Of course you can build a rainbow-table with a list of possible passwords with this salt (the salt is not secret), but if each password got its unique salt, then you would have to build rainbow-tables for each password separately. That means, the salt prevents to use a single rainbow-table to get all passwords at once.
Good to know that i'm rich now, regards from switzerland :-)
来源:https://stackoverflow.com/questions/30315599/understanding-the-purpose-of-a-salt-in-authentication