Beispiel #1
0
        public ActionResult ResetPassword(ResetNewPasswordViewModel _passwordInfo)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View());
                }

                AuthenticatedUser _authUser;

                using (AuthRepository Repo = new AuthRepository())
                {
                    _authUser = Repo.GetAuthenticatedUserById(CurrentUser.EmployeeInfoId);
                }

                if (_authUser.IsFirstTimeLogin == false)
                {
                    return(RedirectToAction("GeneralInfo", "Profile"));
                }

                if (RijndaelCrypt.DecryptPassword(_authUser.PasswordHash, _authUser.Salt) == _passwordInfo.NewPassword)
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("New password should not be same as current password.");

                    return(View());
                }

                var _accountInfo = new AccountInfo();
                _accountInfo.Id               = CurrentUser.AccountId;
                _accountInfo.Salt             = RandomPassword.Generate(18, 20);
                _accountInfo.PasswordHash     = RijndaelCrypt.EncryptPassword(_passwordInfo.NewPassword, _accountInfo.Salt);
                _accountInfo.IsFirstTimeLogin = false;

                using (AccountRepository Repo = new AccountRepository())
                {
                    Repo.ChangeNewPassword(_accountInfo);
                }

                var ctx         = Request.GetOwinContext();
                var authManager = ctx.Authentication;
                authManager.SignOut("ApplicationCookie");

                TempData["Msg"] = "<span style='color:green; text-align:center;'>Password has been reset successfully.</span>";
                return(RedirectToAction("Login", "Auth", new { area = "" }));
            }

            catch (Exception ex)
            {
                TempData["Msg"] = AlertMessageProvider.FailureMessage(ex.ToString());

                return(View());
            }
        }
Beispiel #2
0
        public ActionResult ResetPassword(ResetNewPasswordViewModel passwordInfo)
        {
            try
            {
                if (TempData["AccountId"] == null)
                {
                    return(RedirectToAction("Login", "Auth"));
                }

                if (!ModelState.IsValid)
                {
                    return(View());
                }

                int _accountId   = (int)TempData["AccountId"];
                var _accountInfo = new AccountInfo();

                _accountInfo.Id = _accountId;

                _accountInfo.Salt         = RandomPassword.Generate(18, 20);
                _accountInfo.PasswordHash = RijndaelCrypt.EncryptPassword(passwordInfo.NewPassword, _accountInfo.Salt);

                _accountInfo.IsFirstTimeLogin = false;

                using (AccountRepository Repo = new AccountRepository())
                {
                    Repo.ChangeNewPassword(_accountInfo);
                }

                using (AccountConfirmationRepository Repo = new AccountConfirmationRepository())
                {
                    AccountConfirmationInfo _accountConfirmation = null;

                    _accountConfirmation = Repo.GetAccountConfirmationByAccountId(_accountId);

                    if (_accountConfirmation != null)
                    {
                        Repo.DeleteAccountConfirmation(_accountConfirmation.Id);
                    }
                }

                TempData["Msg"] = "<span style='color:green; text-align:center;'>Password has been reset successfully.</span>";

                return(RedirectToAction("Login", "Auth"));
            }

            catch (Exception ex)
            {
                TempData["Msg"] = "<span style='color:red; text-align:center;'>" + ex.Message.ToString() + ".</span>";
                return(View());
            }
        }