When adding salt values to a hash value for something like a password that cannot be stored in plain text, what is the best place to get the salt values come from? For context, let us suppose this is for passwords on a webpage login.
|
|
I usually have a column
|
|||||
|
|
Does it matter? The salt serves two purposes. It makes it impractical to use large tables of prehashed passwords ("rainbow tables") and it makes identical passwords look different in the list of hashes. Making the identical passwords look different helps avoid a problem where several people are using one particular password, which is presumably a common weak one. Therefore, each account should have its own unique salt, and the salts should not be overly predictable, in the sense that there won't be a group of salts that are likely to occur. (If many sites started at 1 and counted up, bad guys could construct rainbow tables including low-number salts, for example.) They don't have to be random in any sense other than generally unpredictable. They aren't any more secret than the hash itself, so they don't need to be specifically unguessable. Use any convenient method to generate a salt. If there's lots of potential salt values (early Unix systems frequently used two bytes, for a possible number of 65536) compared to the number of accounts, semi-random assignment would almost never give out a duplicate salt. |
|||||||||||||||||||
|
|
Each time you want to store a new password (registration, password-reset, password-update), one good technique is:
|
|||
|
|
|
Leverage the framework. In .NET you could use the RNGCryptoServoiceProvider...
Other frameworks should have similar classes you can leverage. To achieve randomness software often times employs the user versus |
|||
|
|
|
You generate a salt server-side and assign it to a user account upon its creation. Better use some crypto-generation API available with your framework but in principle any sequence will do. Usually things are stored like this:
Example: PasswordHashWithSalt = A15CD9652D4F4A3FB61A2A422AEAFDF0DEA4E703 j5d58k4b56s8744q |
|||||
|