I know This is strange for you because i think em a immature programmer , I am stuck into a situation. i am trying to encrypt user password and authenticate them . here is my code .
String pas="Sun";
String salt = "Oj4zsl3RpCxoXVzkk0EVItepGq82Mv9Hs7W5tFmxKkk=";
String PassHash= getPasswordHashValue(pas, salt);
public static string getPasswordHashValue(string userpassword, string salt)
{
UnicodeEncoding uEncode = new UnicodeEncoding();
byte[] passunicode = uEncode.GetBytes(userpassword);
byte[] bytesalt = uEncode.GetBytes(salt);
byte[] byteresult = new byte[bytesalt.Length + passunicode.Length];
System.Buffer.BlockCopy(passunicode, 0, byteresult, 0, passunicode.Length);
System.Buffer.BlockCopy(bytesalt, 0, byteresult, passunicode.Length, bytesalt.Length);
System.Security.Cryptography.HashAlgorithm ha = HashAlgorithm.Create(Membership.HashAlgorithmType);
return Convert.ToBase64String(ha.ComputeHash(byteresult));
}
Every Times The User Log in it generate Different Hash Code thus the user can not authenticate .As i have stored the hash code of password that has been generated while registering the user in the Database .
this is the debugging watch list result when user log in
select 1 from usertable where username='arif@gmail.com' or email='arif@gmail.com' and
password='ZQ9SsGwO0+Yh3FjxA3luBOwOMZClHN/rzkyF3KI5cXY='
select 1 from usertable where username='arif@gmail.com' or email='arif@gmail.com' and
password='CMKIdNBsb+mCvhYx4EYjywRxLWF2Ygl2Zhr9FsIW+NA='
select 1 from usertable where username='arif@gmail.com' or email='arif@gmail.com' and
password='10WWuTP/NUGr4Uxem3RJdmHyUtnLUcGdWCufS/SQgXI='
as you can see the generated hash code of password is different which is creating problem for authenticating the user.