Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 .

C#
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
SQL
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.
Posted
Updated 31-Jan-15 22:59pm
v2

1 solution

Have a look at this: Password Storage: How to do it.[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900