I am currently working on a project which has clear text passwords. Now we have the requirement to change all the clear text passwords to HASH. The Database has the password field and Password salt field.
I tried the following in .Net (I found .Net 4 uses HMACSHA256 algorithm) to hash the passwords with the salt already in the database.
// I retrieved the password and salt from database and hashed it
string authDetails = row["Password"] + row["PasswordSalt"].ToString(); //password salt - value from database
byte[] authBytes = System.Text.Encoding.UTF8.GetBytes(authDetails);
var hma = new System.Security.Cryptography.HMACSHA256();
byte[] hashedBytes = hma.ComputeHash(authBytes);
string hash = Convert.ToBase64String(hashedBytes);
and stored the above hash var value in the password field.
And I changed the config setting passwordFormat="hashed".
If I try to login with the password, the login fails. I cannot login with old password. Any ideas?
Thanks!
EDIT: just for clarification.. I use asp.net membership provider. I changed the PasswordFormat to 'Hashed' in web.config. Then I call Membership.ValidateUser to validate the logon. - I think it automatically hashes the password entered and matches against database. But i suppose the generated hash by validateuser method is not the same as the hash I generated above.