ValidateUser Method for Entity Framework MVC3 Razor Custom Member Provider C# Using LINQ
From my
C# MVC3 Razor Custom Membership Provider article and source code, here is the code for the ValidateUser method. I welcome any suggestions for improvement.
public override bool ValidateUser(string username, string password)
{
// PasswordFormat = Hashed
byte[] hashedPassword = HashPassword(password.Trim());
// NKT: LINQ to Entities does not recognize
// the method 'Int32 ToInt32(System.Object)' method,
// and this method cannot be translated into a store expression.
int userStatus =
Convert.ToInt32(SSS.GlobalListValues.Enums.UserStatusCode.Active);
using (var context = new SSSEntities())
{
var query =
from u in context.UserProfiles
where u.UserName == username &&
u.UserPassword == hashedPassword &&
u.UserStatusCode == userStatus
select u;
bool isUserFound = false;
foreach (var user in query.Take(1))
{
isUserFound = true;
}
return isUserFound;
}
}
May your dreams be in ASP.NET!
Nannette Thacker