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); }
public ActionResult LogOn(LoginModel model, string returnUrl) { //if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)) //{ if (ModelState.IsValid) { gov_user userInfo = _cnttDB.gov_user.Where(u => u.username.Equals(model.UserName)).FirstOrDefault(); if (userInfo != null) { if (userInfo.password.Equals(FormsAuthentication.HashPasswordForStoringInConfigFile(model.Password, "MD5"))) { Session.SetCurrentUser(userInfo); FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); gov_access_history accessHistory = new gov_access_history(); accessHistory.time_access = DateTime.Now; accessHistory.type_access = (int)AccessType.dangNhap; accessHistory.username_access = userInfo.username; accessHistory.description = Constant.DANG_NHAP; accessHistory.client_info = Utils.GetLanIPAddress(); accessHistory.public_info = Utils.GetPublicIPAddress(); _cnttDB.gov_access_history.Add(accessHistory); _cnttDB.SaveChanges(); return RedirectToLocal(returnUrl); } else { ModelState.AddModelError("", "Tài khoản hoặc mật khẩu nhập vào không chính xác."); return View(model); } } else { ModelState.AddModelError("", "Tài khoản hoặc mật khẩu nhập vào không chính xác."); return View(model); } } //} // If we got this far, something failed, redisplay form //ModelState.AddModelError("", "Tài khoản và mật khẩu không được để trống!"); return View(model); }