Can you teach me more about how does this linq code work? string pass = HashPassword(password)
is a string, HashPassword(password)
returns a string too.
But the LinQ needs a variable to store the string before comparing. Like this:
public bool Login(string email, string password)
{
try
{
string pass = HashPassword(password);
var acc = db.UserAccount.SingleOrDefault(x => x.Email == email && x.HashPassword == pass);
if (acc != null)
{
return true;
}
// email or password is not matched
return false;
}
catch { return false; }
}
and the method to hash password:
private string HashPassword(string password)
{
return BitConverter.ToString(new SHA256CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(password))).Replace("-", "");
}
Since I changed the line var acc = db.UserAccount.SingleOrDefault(x => x.Email == email && x.HashPassword == pass);
to
var acc = db.UserAccount.SingleOrDefault(x => x.Email == email && x.HashPassword == HashPassword(password));
It wouldn't work. Why?