public UserStatus GetUserValidity(UserDetails u) { if (u.UserName == "Admin" && u.Password == "Admin") { return UserStatus.AuthenticatedAdmin; } else if (u.UserName == "Gorm" && u.Password == "Kjeldsen") { return UserStatus.AuthenticatedUser; } else { return UserStatus.NonAuthenticatedUser; } }
public ActionResult DoLogin(UserDetails u) { if (ModelState.IsValid) { EmployeeBusinessLayer empBL = new EmployeeBusinessLayer(); UserStatus status = empBL.GetUserValidity(u); bool IsAdmin = status == UserStatus.AuthenticatedAdmin; if (status == UserStatus.NonAuthenticatedUser) { ModelState.AddModelError("CredentialError", "Invalid Username or Password."); return View("Login"); } FormsAuthentication.SetAuthCookie(u.UserName, false); Session["IsAdmin"] = IsAdmin; return RedirectToAction("Index", "Employee"); } else { return View("Login"); } }