public ActionResult Login(CustomerLogin login) { if (ModelState.IsValid) { try { int custId = CustomerDB.CustomerLogin(login); if (custId == -1) { ModelState.AddModelError("", "Username or password does not match"); return(View(login)); } else { Session["CustomerId"] = custId; return(RedirectToAction("Index")); } } catch { return(View()); } } else { return(View()); } }
protected void btnLogin_Click(object sender, EventArgs e) { Customer cust = new Customer(); cust.CustLoginName = txtUsername.Text; cust.CustPassword = txtpassword.Text; if (custDB.CustomerLogin(cust)) { //Redirect to dashboard Session["loggedin"] = true; Session["CustID"] = cust.CustomerID; Response.Redirect("~/dashboard/index.aspx"); } else { lblErrorMessage.Text = "Error in Login"; } }
// POST: public ActionResult Login(CustomerLogin login) { if (ModelState.IsValid) { try { int custId = CustomerDB.CustomerLogin(login); Session["CustomerId"] = custId; return(RedirectToAction("Index")); } catch { return(View()); } } else { return(View()); } }
public ActionResult Login(CustomerLogin login) { Customer databaseUser = new Customer(); databaseUser = CustomerDB.CustomerLogin(login.UserName); if (ModelState.IsValid) { if (databaseUser is null) { //ModelState.AddModelError("Error", "User Name is Registered"); ViewBag.invalid = "Invalid User"; return(View()); } else { var databasePassword = databaseUser.Password; //if(databaseUser.Password != Crypto.Hash(login.Password)) int results = (string.Compare(Crypto.Hash(login.Password), databasePassword)); if (results != 0) { ViewBag.Password = "******"; return(View()); } else { Session["UserID"] = databaseUser.CustomerId; Session["CustFirstName"] = databaseUser.CustFirstName; } } } return(RedirectToAction("Index", "Customer")); }