/// <summary>
        /// Create the default credential dialog.
        /// </summary>
        /// <param name="targetName">The target name.</param>
        /// <returns>The credential dialog.</returns>
        public static PromptDialogOptions Create(string targetName)
        {
            PromptDialogOptions dialog = new PromptDialogOptions();

            dialog.AlwaysShowUI         = false;
            dialog.Banner               = null;
            dialog.CompleteUserName     = false;
            dialog.DoNotPersist         = false;
            dialog.ErrorCode            = 0;
            dialog.ExcludeCertificates  = false;
            dialog.ExpectConfirmation   = false;
            dialog.GenericCredentials   = false;
            dialog.IncorrectPassword    = false;
            dialog.Message              = string.Empty;
            dialog.Password             = string.Empty;
            dialog.Persist              = false;
            dialog.RequestAdministrator = false;
            dialog.RequireCertificate   = false;
            dialog.RequireSmartCard     = false;
            dialog.SaveChecked          = false;
            dialog.ShowSaveCheckBox     = false;
            dialog.Title            = string.Empty;
            dialog.UserName         = string.Empty;
            dialog.UserNameReadOnly = false;
            dialog.ValidateUserName = false;
            dialog.TargetName       = targetName;
            return(dialog);
        }
        /// <summary>
        /// Show the prompt for credentials dialog window.
        /// </summary>
        /// <param name="owner">The windows form prompt dialog owner.</param>
        /// <param name="options">The prompt options.</param>
        /// <returns>The prompt credential result: else null;</returns>
        public PromptDialogResult ShowPromptForCredentialsDialog(System.Windows.Forms.IWin32Window owner, PromptDialogOptions options)
        {
            PromptDialogResult result = null;

            try
            {
                // Create a new credential dialog window.
                using (PromptForCredential prompt = new PromptForCredential())
                {
                    prompt.TargetName = options.TargetName;
                    prompt.UserName   = options.UserName;

                    prompt.Password = new SecureString();
                    foreach (char element in options.Password)
                    {
                        prompt.Password.AppendChar(element);
                    }

                    prompt.Title     = options.Title;
                    prompt.Message   = options.Message;
                    prompt.ErrorCode = options.ErrorCode;

                    if (!String.IsNullOrEmpty(options.Banner))
                    {
                        prompt.Banner = new Bitmap(options.Banner);
                    }

                    prompt.SaveChecked          = options.SaveChecked;
                    prompt.AlwaysShowUI         = options.AlwaysShowUI;
                    prompt.CompleteUserName     = options.CompleteUserName;
                    prompt.DoNotPersist         = options.DoNotPersist;
                    prompt.ExcludeCertificates  = options.ExcludeCertificates;
                    prompt.ExpectConfirmation   = options.ExpectConfirmation;
                    prompt.GenericCredentials   = options.GenericCredentials;
                    prompt.IncorrectPassword    = options.IncorrectPassword;
                    prompt.Persist              = options.Persist;
                    prompt.RequestAdministrator = options.RequestAdministrator;
                    prompt.RequireCertificate   = options.RequireCertificate;
                    prompt.RequireSmartCard     = options.RequireSmartCard;
                    prompt.ShowSaveCheckBox     = options.ShowSaveCheckBox;
                    prompt.UserNameReadOnly     = options.UserNameReadOnly;
                    prompt.ValidateUserName     = options.ValidateUserName;

                    DialogResult dialogResult;
                    if (owner == null)
                    {
                        dialogResult = prompt.ShowDialog();
                    }
                    else
                    {
                        dialogResult = prompt.ShowDialog(owner);
                    }

                    // Show the dialog.
                    if (DialogResult.OK == dialogResult)
                    {
                        // Create the result.
                        result = new PromptDialogResult();

                        result.SaveChecked = prompt.SaveChecked;
                        result.UserName    = prompt.UserName;

                        IntPtr passwordBstr = IntPtr.Zero;

                        try
                        {
                            // Convert the password pointer data.
                            passwordBstr    = Marshal.SecureStringToBSTR(prompt.Password);
                            result.Password = Marshal.PtrToStringBSTR(passwordBstr);
                        }
                        finally
                        {
                            if (IntPtr.Zero != passwordBstr)
                            {
                                Marshal.FreeBSTR(passwordBstr);
                            }
                        }

                        // Confirm the credentials.
                        if (prompt.ExpectConfirmation && prompt.SaveChecked)
                        {
                            prompt.ConfirmCredentials();
                        }
                    }
                }

                // Return the result.
                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
 /// <summary>
 /// Show the prompt for credentials dialog window.
 /// </summary>
 /// <param name="options">The prompt options.</param>
 /// <returns>The prompt credential result: else null;</returns>
 public PromptDialogResult ShowPromptForCredentialsDialog(PromptDialogOptions options)
 {
     return(ShowPromptForCredentialsDialog(null, options));
 }