Exemple #1
0
        private bool ValidateSpecifiedPasswords(string oldPassword, string newPassword, string newPasswordConfirmed)
        {
            string currentUserName = UserValidationFacade.GetUsername();

            bool oldPasswordCorrect = UserValidationFacade.FormValidateUserWithoutLogin(currentUserName, oldPassword);

            if (!oldPasswordCorrect)
            {
                this.ShowFieldMessage(Fields.OldPassword, Texts.ChangeOwnPasswordWorkflow_Dialog_Validation_IncorrectPassword);
                return(false);
            }

            if (newPassword != newPasswordConfirmed)
            {
                this.ShowFieldMessage(Fields.NewPasswordConfirmed, Texts.ChangeOwnPasswordWorkflow_Dialog_Validation_NewPasswordFieldsNotMatch);
                return(false);
            }

            if (newPassword == oldPassword)
            {
                this.ShowFieldMessage(Fields.NewPassword, Texts.ChangeOwnPasswordWorkflow_Dialog_Validation_PasswordsAreTheSame);
                return(false);
            }

            if (string.IsNullOrEmpty(newPassword))
            {
                this.ShowFieldMessage(Fields.NewPassword, Texts.ChangeOwnPasswordWorkflow_Dialog_Validation_NewPasswordIsEmpty);
                return(false);
            }

            string userName = UserValidationFacade.GetUsername();

            var user = DataFacade.GetData <IUser>(u => string.Compare(u.Username, userName, StringComparison.InvariantCultureIgnoreCase) == 0)
                       .FirstOrException("No user found with name '{0}'", userName);

            IList <string> newPasswordValidationMessages;

            if (!PasswordPolicyFacade.ValidatePassword(user, newPassword, out newPasswordValidationMessages))
            {
                foreach (var message in newPasswordValidationMessages)
                {
                    this.ShowFieldMessage(Fields.NewPassword, message);
                }
                return(false);
            }

            return(true);
        }