Example #1
0
 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());
     }
 }
Example #2
0
        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";
            }
        }
Example #3
0
 // 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"));
        }