Exemplo n.º 1
0
        // GET: Home/Hash
        public ActionResult Hash()
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(View("NotLoggedIn"));
            }

            if (User.Identity.AuthenticationType.StartsWith("HASHED"))
            {
                return(View("AlreadyHashed"));
            }

            if (User.Identity.AuthenticationType.StartsWith("IMPERSONATED"))
            {
                return(View("ActionNotAllowed"));
            }

            using (BusinessLogicLayer.ContextBLL ctx = new BusinessLogicLayer.ContextBLL())
            {
                BusinessLogicLayer.UserBLL user = ctx.User_FindByUserName(User.Identity.Name);
                if (user == null)
                {
                    Exception Message = new Exception($"The Username '{User.Identity.Name}' does not exist in the database");
                    ViewBag.Exception = Message;
                    return(View("Error"));
                }
                user.PasswordSalt = System.Web.Helpers.Crypto.GenerateSalt(Constants.SaltSize);
                user.PasswordHash = System.Web.Helpers.Crypto.HashPassword(user.PasswordHash + user.PasswordSalt);
                ctx.User_JustUpdate(user);

                string ValidationType = $"HASHED:({user.UserID})";

                Session["AUTHUsername"] = user.UserEmail;
                Session["AUTHRoles"]    = user.RoleName;
                Session["AUTHTYPE"]     = ValidationType;

                return(RedirectToAction("Index", "Home"));
            }
        }