/// <summary>
        /// Returns the flags for dialog display options.
        /// </summary>
        private NativeCredentialsUI.FLAGS GetFlags()
        {
            NativeCredentialsUI.FLAGS flags = NativeCredentialsUI.FLAGS.GENERIC_CREDENTIALS;

            if (this.AlwaysDisplay)
            {
                flags = flags | NativeCredentialsUI.FLAGS.ALWAYS_SHOW_UI;
            }

            if (this.ExcludeCertificates)
            {
                flags = flags | NativeCredentialsUI.FLAGS.EXCLUDE_CERTIFICATES;
            }

            if (this.Persist)
            {
                flags = flags | NativeCredentialsUI.FLAGS.PERSIST;
                flags = flags | NativeCredentialsUI.FLAGS.EXPECT_CONFIRMATION;
            }
            else
            {
                flags = flags | NativeCredentialsUI.FLAGS.DO_NOT_PERSIST;
            }

            if (this.KeepName)
            {
                flags = flags | NativeCredentialsUI.FLAGS.KEEP_USERNAME;
            }

            if (this.ValidName)
            {
                flags = flags | NativeCredentialsUI.FLAGS.VALIDATE_USERNAME;
            }

            return(flags);
        }
        /// <summary>
        /// Returns a DialogResult indicating the user action.
        /// </summary>
        /// <param name="owner">The System.Windows.Forms.IWin32Window the dialog will display in front of.</param>
        /// <remarks>
        /// Sets the name, password and SaveChecked accessors to the state of the dialog as it was dismissed by the user.
        /// </remarks>
        private DialogResult ShowDialog(IWin32Window owner)
        {
            // set the api call parameters
            StringBuilder name = new StringBuilder(NativeCredentialsUI.MAX_USERNAME_LENGTH);

            name.Append(this.Name);

            StringBuilder password = new StringBuilder(NativeCredentialsUI.MAX_PASSWORD_LENGTH);

            int saveChecked = Convert.ToInt32(this.SaveChecked);

            NativeCredentialsUI.INFO  info  = GetInfo(owner);
            NativeCredentialsUI.FLAGS flags = GetFlags();

            // make the api call
            NativeCredentialsUI.ReturnCodes code = NativeCredentialsUI.PromptForCredentials(
                ref info,
                this.Target,
                IntPtr.Zero, 0,
                name, NativeCredentialsUI.MAX_USERNAME_LENGTH,
                password, NativeCredentialsUI.MAX_PASSWORD_LENGTH,
                ref saveChecked,
                flags
                );

            // set the accessors from the api call parameters
            this.Name = name.ToString();
            foreach (char c in password.ToString())
            {
                this.Password.AppendChar(c);
            }
            this.Password.MakeReadOnly();
            this.SaveChecked = Convert.ToBoolean(saveChecked);

            return(GetDialogResult(code));
        }