I am trying to store the hashed password in the database. Like given below.
Md5Encrypt.Md5EncryptPassword(viewModel.User.PasswordHash);
Textual Password : TestBasant1900
And it get stored in my Database table in sql server like this after passing this into Md5Encrypt : zb??"??8?(Y???0z
When I am trying to check the password in Database and current user logged in password :
public bool Login(string userName, string password)
{
try
{
using (var db1 = new DBEnitityObj)
{
var user = (from u in db1.ftUsers
where (u.UserName == userName && u.IsApproved == true)
select u).First();
var PasswordHash1 = user.PasswordHash;
var encoded = Md5Encrypt.Md5EncryptPassword(password);
// It fails in the below condition
return user.PasswordHash.Equals(encoded);
}
}
catch
{
return false;
}
}
It fails in the below condition since the hashed password over here will return this : zb��"��8�(Y���0z
I am using this for md5 Hashing
public static string Md5EncryptPassword(string data)
{
var encoding = new ASCIIEncoding();
var bytes = encoding.GetBytes(data);
var hashed = MD5.Create().ComputeHash(bytes);
return Encoding.UTF8.GetString(hashed);
}
Can any one please tell me what is hashed password is not getting matched with password which I enter on the user interface
zb��"��8�(Y���0z is not equal to zb??"??8?(Y???0z
Can some one guide me what to do guys. Thanks in advance.