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));
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            while (true)
            {
                PwordHash p = new PwordHash();

                string password = Console.ReadLine();

                string storedSaltHash = p.SQLSaltHashStore(password);

                Console.WriteLine(storedSaltHash);
                Console.ReadKey();

                string password2 = Console.ReadLine();

                bool check = p.LoginCheck(password2, storedSaltHash);
            }
        }