Esempio n. 1
0
        public ActionResult LoginAuthentication(string userName, string password, bool RememberBox)
        {
            Security           active      = new Security();
            var                UController = new UsersController();
            SecurityController SController = new SecurityController(active);
            IVM                model       = new LoginVM(active.IsLoggedIn, active);

            var user = UController.GetU(userName);

            if (user != null)
            {
                var saltHash        = user.PassSalt;
                var encodedPassword = UController.HashPassword(password, saltHash);
                if (user.PassHash.Trim() == encodedPassword.Trim())
                {
                    SController.Login(userName);
                    SController.SetRemember(RememberBox);
                    Login(SController);
                    model = new InventoryVM(userName.Trim(), SController.GetActive());
                    return(View("Inventory", model));
                }
                else
                {
                    ViewBag.ErrorMessage = "Invalid Password";
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Invalid User Name";
            }

            return(View("Index", model));
        }
Esempio n. 2
0
        public SecurityController IsLoggedIn(SecurityController active)
        {
            bool       value       = false;
            string     decodedUser = "";
            bool       remember    = false;
            HttpCookie cookie      = Request.Cookies["UserInfo"];

            if (cookie != null)
            {
                decodedUser = HttpUtility.HtmlDecode(cookie.Values["ID"]);
                value       = HttpUtility.HtmlDecode(cookie.Values["LoggedIn"]).Equals("True");
                remember    = HttpUtility.HtmlDecode(cookie.Values["Remember"]).Equals("True");
            }
            if (value)
            {
                active.Login(decodedUser);
                active.SetRemember(remember);
            }
            return(active);
        }