public ActionResult LogOn(LoginViewModel model) { if (ModelState.IsValid) { var hash = FormsAuthentication.HashPasswordForStoringInConfigFile(model.Password, FormsAuthPasswordFormat.SHA1.ToString()); if (_service.UserFound(model.UserName, hash)) { FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } ModelState.AddModelError(String.Empty, "Username or password is incorrect"); } return View(model); }
public ActionResult Register(LoginViewModel newRegistration) { if (ModelState.IsValid) { if (!_service.UsernameExists(newRegistration.UserName)) { var hash = FormsAuthentication.HashPasswordForStoringInConfigFile(newRegistration.Password, FormsAuthPasswordFormat.SHA1.ToString()); _service.AddUser(newRegistration.UserName, hash); FormsAuthentication.SetAuthCookie(newRegistration.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError(String.Empty, "This username is already taken."); } } return View(newRegistration); }