コード例 #1
0
        private UserCredentials PromptForCredentials(string url)
        {
            UserCredentials   result = null;
            CredentialsDialog dialog = new CredentialsDialog("Kato - Jenkins Authentication : \r\n" + url);

            if (dialog.Show() == DialogResult.OK && (!String.IsNullOrWhiteSpace(dialog.Password) && !String.IsNullOrWhiteSpace(dialog.Name)))
            {
                var creds = new UserCredentials {
                    UserName = dialog.Name, Password = dialog.Password
                };

                if (!TryToAuthenticate(url, creds))
                {
                    return(null);
                }

                if (dialog.SaveChecked)
                {
                    dialog.Confirm(true);
                }
                result = creds;
            }

            return(result);
        }
コード例 #2
0
ファイル: CredentialsHelper.cs プロジェクト: zetz/kato
        public static UserCredentials PromptForCredentials(string url, bool forceDisplay = false)
        {
            UserCredentials   result = null;
            CredentialsDialog dialog = new CredentialsDialog("Kato - Jenkins Authentication : \r\n" + url)
            {
                AlwaysDisplay = forceDisplay, SaveDisplayed = false
            };

            if (dialog.Show(saveChecked: true) == DialogResult.OK && (!string.IsNullOrWhiteSpace(dialog.Password) && !string.IsNullOrWhiteSpace(dialog.Name)))
            {
                var creds = new UserCredentials {
                    UserName = dialog.Name, Password = dialog.Password
                };

                if (!TryToAuthenticate(url, creds))
                {
                    return(null);
                }

                if (dialog.SaveChecked)
                {
                    dialog.Confirm(true);
                }

                result = creds;
            }

            return(result);
        }
コード例 #3
0
ファイル: JiraConnector.cs プロジェクト: vituocgia/vietshot
        /// <summary>
        ///     Use the credentials dialog, this will show if there are not correct credentials.
        ///     If there are credentials, call the real login.
        /// </summary>
        /// <returns>Task</returns>
        public async Task LoginAsync(CancellationToken cancellationToken = default)
        {
            await LogoutAsync(cancellationToken);

            try
            {
                // Get the system name, so the user knows where to login to
                var credentialsDialog = new CredentialsDialog(_jiraConfiguration.Url)
                {
                    Name = null
                };
                while (credentialsDialog.Show(null, credentialsDialog.Name) == DialogResult.OK)
                {
                    if (await DoLoginAsync(credentialsDialog.Name, credentialsDialog.Password, cancellationToken))
                    {
                        if (credentialsDialog.SaveChecked)
                        {
                            credentialsDialog.Confirm(true);
                        }
                        IsLoggedIn    = true;
                        _loggedInTime = DateTime.Now;
                        return;
                    }
                    // Login failed, confirm this
                    try
                    {
                        credentialsDialog.Confirm(false);
                    }
                    catch (ApplicationException e)
                    {
                        // exception handling ...
                        Log.Error().WriteLine(e, "Problem using the credentials dialog");
                    }
                    // For every windows version after XP show an incorrect password baloon
                    credentialsDialog.IncorrectPassword = true;
                    // Make sure the dialog is display, the password was false!
                    credentialsDialog.AlwaysDisplay = true;
                }
            }
            catch (ApplicationException e)
            {
                // exception handling ...
                Log.Error().WriteLine(e, "Problem using the credentials dialog");
            }
        }
コード例 #4
0
ファイル: Confluence.cs プロジェクト: Vistritium/greenshot
 public void Login()
 {
     Logout();
     try
     {
         // Get the system name, so the user knows where to login to
         var systemName = _url.Replace(DEFAULT_POSTFIX1, "");
         systemName = systemName.Replace(DEFAULT_POSTFIX2, "");
         var dialog = new CredentialsDialog(systemName)
         {
             Name = null
         };
         while (dialog.Show(null, dialog.Name) == DialogResult.OK)
         {
             if (DoLogin(dialog.Name, dialog.Password))
             {
                 if (dialog.SaveChecked)
                 {
                     dialog.Confirm(true);
                 }
                 return;
             }
             try
             {
                 dialog.Confirm(false);
             }
             catch (ApplicationException e)
             {
                 // exception handling ...
                 Log.Error().WriteLine(e, "Problem using the credentials dialog");
             }
             // For every windows version after XP show an incorrect password baloon
             dialog.IncorrectPassword = true;
             // Make sure the dialog is display, the password was false!
             dialog.AlwaysDisplay = true;
         }
     }
     catch (ApplicationException e)
     {
         // exception handling ...
         Log.Error().WriteLine(e, "Problem using the credentials dialog");
     }
 }
コード例 #5
0
 public void login()
 {
     logout();
     try {
         // Get the system name, so the user knows where to login to
         string systemName = url.Replace(ConfluenceConfiguration.DEFAULT_POSTFIX1, "");
         systemName = url.Replace(ConfluenceConfiguration.DEFAULT_POSTFIX2, "");
         CredentialsDialog dialog = new CredentialsDialog(systemName);
         dialog.Name = null;
         while (dialog.Show(dialog.Name) == DialogResult.OK)
         {
             if (doLogin(dialog.Name, dialog.Password))
             {
                 if (dialog.SaveChecked)
                 {
                     dialog.Confirm(true);
                 }
                 return;
             }
             else
             {
                 try {
                     dialog.Confirm(false);
                 } catch (ApplicationException e) {
                     // exception handling ...
                     LOG.Error("Problem using the credentials dialog", e);
                 }
                 // For every windows version after XP show an incorrect password baloon
                 dialog.IncorrectPassword = true;
                 // Make sure the dialog is display, the password was false!
                 dialog.AlwaysDisplay = true;
             }
         }
     } catch (ApplicationException e) {
         // exception handling ...
         LOG.Error("Problem using the credentials dialog", e);
     }
 }
コード例 #6
0
        public void SetDialogConfirm(IGitCredential gitCredential, bool isConfirmed)
        {
            try
            {
                CredentialsDialog credentialsDialog = (gitCredential as GitCredential)?.Dialog;

                if (credentialsDialog == null)
                {
                    return;
                }

                if (!isConfirmed)
                {
                    // Provided credentials where not valid
                    Track.Event("CredentialsDialog-Denied");
                    credentialsDialog.Confirm(false);
                    bool isDeleted = credentialsDialog.Delete();
                    Log.Debug($"Deleted: {isDeleted}");
                }
                else if (credentialsDialog.SaveChecked)
                {
                    // Provided credentials where valid and user want them to be cached
                    Track.Event("CredentialsDialog-Confirmed");
                    credentialsDialog.Confirm(true);
                }
                else
                {
                    // User did not want valid credentials to be cached
                    Track.Event("CredentialsDialog-NotCached");
                }
            }
            catch (ApplicationException e)
            {
                Log.Exception(e, "");
            }
        }
コード例 #7
0
        // References:
        // http://msdn.microsoft.com/en-us/library/aa480470.aspx

        /// <summary>
        /// Accepts a user credentials if they haven't been saved or if they have changed, adds them to the credential cache, and makes
        /// a call to EWS to verify that the credentials work. If the credentials work, then a confirmation is sent to the credential
        /// manager and the credentials are provided back to the application to be used to make EWS calls.
        /// </summary>
        internal static bool AppLogin(IWin32Window owner, IUserData data, ref ExchangeService service)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(data.UserName) ||
                    string.IsNullOrWhiteSpace(data.Password))
                {
                    // Create the credential prompt that will handle the user credentials.
                    //CredPrompt prompt = new CredPrompt(@"Exchange Web Services (EWS)");
                    CredentialsDialog dlg = new CredentialsDialog(
                        @"Exchange Web Services (EWS)", "EWS credentials", "Enter your credentials");

                    // Show the prompt. This will either prompt for the user credentials or, if they
                    // already exist on the system, it will load credentials from the cache in the CredDialog object.
                    //DialogResult result = prompt.ShowPrompt();
                    DialogResult result = dlg.Show(owner, true);

                    if (result == DialogResult.OK)
                    {
                        // Authenticate the credentials and if they work, confirm the credentials and provide the
                        // ExchangeService object back to the application.
                        string[] parts = dlg.Name.Split('\\');
                        switch (parts.Length)
                        {
                        case 1:
                            data.UserName = parts[0];
                            break;

                        default:
                            data.Domain   = parts[0];
                            data.UserName = parts[1];
                            break;
                        }
                        data.Password = dlg.Password;

                        if (Authenticate(data, ref service))
                        {
                            // The credentials were authenticated. Confirm that we want the
                            // credential manager to save our credentials.
                            if (dlg.SaveChecked)
                            {
                                dlg.Confirm(true);
                            }
                            return(true);
                        }
                        // The credentials were not authenticated.
                        try
                        {
                            dlg.Confirm(false);
                            return(false);
                        }
                        catch (ApplicationException)
                        {
                            // Prompt user for credentials again. We may need to provide a way to break
                            while (true)
                            {
                                DialogResult res = MessageBox.Show(
                                    LocalizibleStrings.RetryConnection,
                                    Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                                return(res == DialogResult.Yes && AppLogin(owner, data, ref service));
                            }
                        }
                    }

                    if (result != DialogResult.Cancel)
                    {
                        throw new ApplicationException(LocalizibleStrings.UnhandledCondition + result);
                    }
                }
                else
                {
                    return(Authenticate(data, ref service));
                }
            }
            // This will capture errors stemming from CredUICmdLinePromptForCredentials.
            catch (ApplicationException exc)
            {
                Logger.Error(@"AppLogin", exc);
            }

            return(false);
        }
コード例 #8
0
        /// <summary>
        /// If proxy auth is required then the proxy password is retrieved from saved credentials
        /// or requested from the user. This is repeated until the WebRequestFunction succeeds
        /// (upon which the credentials are saved), or the user cancels.
        /// </summary>
        private object ProxyAuthHandler(WebRequestFunction func, Object arg, out Object ret, out WebException proxyAuthException)
        {
            if (!IsProxyAuthRequired(func, arg, out ret, out proxyAuthException))
            {
                return(ret);
            }


            // got HTTP 407

            // extract realm

            string realm = proxyAuthException.Response.Headers[HttpResponseHeader.ProxyAuthenticate];

            Match match = Regex.Match(realm, @"realm=\""(.+?)\""", RegexOptions.IgnoreCase); // eg,  "Basic realm=\"The realm name\""  (inc quotes)

            if (match.Success)
            {
                realm = match.Groups[1].Value;
            }
            else if (WebRequest.DefaultWebProxy is WebProxy) // custom
            {
                realm = ((WebProxy)WebRequest.DefaultWebProxy).Address.Host;
            }
            else
            {
                realm = Language.NetManager_PleaseEnterCredentials;
            }


            // ask for credentials until succeeds or cancelled

            while (true)
            {
                // remove save check if auth failed

                if (WebRequest.DefaultWebProxy.Credentials != null)
                {
                    proxyCredDialog.SaveChecked = false;
                }


                // get proxy credentials (prompt if not stored)

                NetworkCredential cred = GetProxyCredentials(realm);
                if (cred == null)
                {
                    throw proxyAuthException;         // user cancelled, return original 407 exception
                }
                WebRequest.DefaultWebProxy.Credentials = cred;


                // try again

                if (!IsProxyAuthRequired(func, arg, out ret, out proxyAuthException)) // success
                {
                    proxyCredDialog.AlwaysDisplay = false;

                    try
                    {
                        if (proxyCredDialog.SaveChecked)
                        {
                            proxyCredDialog.Confirm(true); // store
                        }
                        else
                        {
                            proxyCredDialog.Confirm(false); // unstore
                        }
                    }
                    catch { }

                    return(ret);
                }
                else // failed again
                {
                    proxyCredDialog.AlwaysDisplay = true;
                    proxyCredDialog.Password      = "";

                    try // throws an exception if didn't actually show dialog (ie, stored password was wrong)
                    {
                        proxyCredDialog.Confirm(false);
                    }
                    catch { }
                }
            } // end while
        }