public ActionResult Login(User model) { if (model.EmailAddress == "" || model.EmailAddress == null) { return(View("Login", model)); } User thisGuy = _brew.LoginUser(model.EmailAddress); PwordHash p = new PwordHash(); bool verifyPassWord = p.LoginCheck(model.Password, thisGuy.SaltHash); if (thisGuy == null || verifyPassWord == false) { ModelState.AddModelError("invalid-credentials", "An invalid username or password was provided"); return(View("Login", model)); } //if (model.Password == thisGuy.Password && model != null) if (verifyPassWord == true && model != null) { FormsAuthentication.SetAuthCookie(model.EmailAddress, true); Session[SessionKey.Email] = thisGuy.EmailAddress; Session[SessionKey.UserID] = thisGuy.UserName; Session["UserId"] = thisGuy.UserId; if (thisGuy.IsBrewer == true) { Session["BreweryId"] = thisGuy.BreweryId; } else { Session["BreweryId"] = null; } if (thisGuy.IsAdmin) { Session["Admin"] = true; } else { Session["Admin"] = null; } Session["LoggedIn"] = "true"; return(RedirectToAction("Index", "Home")); } else { return(View("Login", model)); } }
public ActionResult Login(User model) { if (model.EmailAddress == "" || model.EmailAddress == null) { return(View("Login", model)); } string emailAddress = model.EmailAddress; User thisGuy = _brew.LoginUser(emailAddress); if (thisGuy == null || thisGuy.Password != model.Password) { ModelState.AddModelError("invalid-credentials", "An invalid username or password was provided"); return(View("Login", model)); } if (model.Password == thisGuy.Password && model != null) { FormsAuthentication.SetAuthCookie(model.EmailAddress, true); Session[SessionKey.Email] = thisGuy.EmailAddress; Session[SessionKey.UserID] = thisGuy.UserName; Session["UserId"] = thisGuy.UserId; if (thisGuy.IsBrewer == true) { Session["BreweryId"] = thisGuy.BreweryId; } else { Session["BreweryId"] = null; } if (thisGuy.IsAdmin) { Session["Admin"] = true; } else { Session["Admin"] = null; } Session["LoggedIn"] = "true"; return(RedirectToAction("Index", "Home")); } else { return(View("Login", model)); } }