Last post Aug 09, 2011 01:52 PM by vatsaldesai24
Aug 07, 2011 01:47 AM|vatsaldesai24|LINK
I am using below method to encode password and save it into database.
static string EncodePassword(string pass, string salt)
byte bIn = Encoding.Unicode.GetBytes(pass);
byte bSalt = Convert.FromBase64String(salt);
byte bAll = new byte[bSalt.Length + bIn.Length];
byte bRet = null;
Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length);
Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length);
HashAlgorithm s = HashAlgorithm.Create(Membership.HashAlgorithmType); // SHA1
bRet = s.ComputeHash(bAll);
Above method was working fine when I was running my project on Framework 3.5. If I change my project framework veirsion to 4.0 the above method returns me defferent string for same pass, and same salt each time. Becase of this problem even user enter same
password on login page, he/she can't login.
I try to search on google and msdn but I could not found any proper reason. Can any one help me to find out the correct reasion that why this method is working in 3.5 and not in 4.0.
Aug 08, 2011 09:34 AM|GPankaj|LINK
The default Hash algorithm in .Net 4.0 is changed to SHA1, which uses the HMACSHA1 algorithm. You need to override the HashAlgorithmType property of your membership provider. The default settings for the <pages> and <machineKey> elements are defined in the
machine-level web.config.comments file.
Please refer this link
Hope this helps
Aug 09, 2011 01:52 PM|vatsaldesai24|LINK
You solved my problem :)