Search code examples
c#entity-frameworkdata-access-layer

Login Form With Entity Framework and 3 layer architecture


I want to write a login form.

How much my code is correct? please guide me.

PhonebookDatabaseEntities context = new PhonebookDatabaseEntities();

public bool Accunt(string username ,string password)
{

    bool exists = context.Users.Where(u => u.UserName == username && u.Password == password);
    return exists;
}

Solution

  • it's not clear yr question. if context.Users.Where(u => u.UserName == username && u.Password == password); works correctly then it fine but it would be better u return the user

    public User Accunt(string username ,string password) 
    {
      return context.Users.FirstOrDefault(u => u.UserName == username && u.Password == password); 
    }
    

    and later on u can check if it's null then credentials are wrong otherwise u check if u.IsActive ... u create appropriate messages for user in BLL and yr UI layer display them to client.