简体   繁体   中英

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;
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM