Understanding the purpose of a salt in authentication

不打扰是莪最后的温柔 提交于 2021-01-28 20:11:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!