Does it matter how I add a salt to a password in my application: by appending it or by prepending?
# 1
res = sha256(salt + password)
# 2
res2 = sha256(password + salt)
I've been told that the 2nd option is better.
Does it matter how I add a salt to a password in my application: by appending it or by prepending?
# 1
res = sha256(salt + password)
# 2
res2 = sha256(password + salt)
I've been told that the 2nd option is better.
This scenario doesn't really apply to password storage, but more for trying to use a standard hash to validate user input.
The reason data+salt is better is because it makes it more difficult to perform a Length Extention Attack The assumption here is that the user does not control the salt, but does control the data. If the user can control the end of the input to a hash, he/she can control/predict what the hash will look like. This link can give you a better idea of how length extention attacks work
Also, don't ever use sha256 to hash passwords. Use some sort of Key Derivation Function, like BCrypt.