public ActionResult Login(LoginModel loginData, string returnUrl) { if (ModelState.IsValid) { if (FormsAuthentication.Authenticate(loginData.Username, loginData.Password)) { FormsAuthentication.SetAuthCookie(loginData.Username, false); return Redirect(returnUrl); } else { ModelState.AddModelError("", "Username and/or password are not correct"); } } return View(loginData); }
public ActionResult Login(LoginModel loginData, string returnUrl) { if (ModelState.IsValid) { string encryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(loginData.Password, "MD5"); UserRepository users=new UserRepository(); UserDetails user = users.GetUserByName(loginData.Username, encryptedPassword); if (user!=null) { FormsAuthentication.SetAuthCookie(loginData.Username, false); return Redirect(returnUrl); } else { ModelState.AddModelError("", "Username and/or password are not correct"); } } return View(loginData); }