public ActionResult Login(LoginModel loginModel) { if (ModelState.IsValid) { var user = _userRepository.Get(x => x.UserName == loginModel.UserName).SingleOrDefault(); if (user != null && PasswordHash.ValidatePassword(loginModel.Password, user.Password)) { FormsAuthHelper.SetAuthTicket(user, HttpContext); return RedirectToAction("Index", "Home"); } ModelState.AddModelError("NotFound", "User not found"); } return View(loginModel); }
public ActionResult Login(LoginModel model, string returnUrl) { if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) { return RedirectToLocal(returnUrl); } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); return View(model); }