private bool ShowYesNo(GitCredentialItem item) { var result = Context.GetService<IVisualGitDialogOwner>() .MessageBox.Show(item.PromptText, Properties.Resources.Credentials, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); item.YesNoValue = result == DialogResult.Yes; return result != DialogResult.Cancel; }
private void UpdateCache(string uri, GitCredentialItem item) { _runCache[GetCacheKey(uri, item)] = new CredentialCacheItem( uri, item.Type.ToString(), item.PromptText, item.Value ); }
private bool ShowInformation(GitCredentialItem item) { Context.GetService<IVisualGitDialogOwner>() .MessageBox.Show(item.PromptText, Properties.Resources.Credentials, MessageBoxButtons.OK, MessageBoxIcon.Information); return true; }
private bool ShowGeneric(GitCredentialItem item, ref bool rememberPassword) { using (var dialog = new GenericCredentialsDialog()) { dialog.Item = item; dialog.RememberPassword = rememberPassword; bool result = dialog.ShowDialog(Context, this) == DialogResult.OK; if (result) rememberPassword = dialog.RememberPassword; return result; } }
private bool ProcessCached(string uri, GitCredentialItem item) { lock (_syncLock) { switch (item.Type) { case GitCredentialsType.Password: case GitCredentialsType.String: case GitCredentialsType.Username: CredentialCacheItem result; if (_runCache.TryGetValue(GetCacheKey(uri, item), out result)) { item.Value = result.Response; return true; } else { var cacheItem = ConfigurationService.GetCredentialCacheItem( uri, item.Type.ToString(), item.PromptText ); if (cacheItem != null) { item.Value = cacheItem.Response; return true; } } break; } } return false; }
private void GetUserNamePasswordWindows(GitCredentialsEventArgs e, string description, GitCredentialItem usernameItem, GitCredentialItem passwordItem, ref bool rememberPassword) { NativeMethods.CREDUI_INFO info = new NativeMethods.CREDUI_INFO(); info.pszCaptionText = Properties.Resources.ConnectToGit; info.pszMessageText = description; info.hwndParent = IntPtr.Zero; info.cbSize = Marshal.SizeOf(typeof(NativeMethods.CREDUI_INFO)); StringBuilder sbUserName = new StringBuilder("", 1024); StringBuilder sbPassword = new StringBuilder("", 1024); var flags = NativeMethods.CREDUI_FLAGS.GENERIC_CREDENTIALS | NativeMethods.CREDUI_FLAGS.ALWAYS_SHOW_UI | NativeMethods.CREDUI_FLAGS.DO_NOT_PERSIST | NativeMethods.CREDUI_FLAGS.SHOW_SAVE_CHECK_BOX; var result = NativeMethods.CredUIPromptForCredentials( ref info, e.Uri, IntPtr.Zero, 0, sbUserName, 1024, sbPassword, 1024, ref rememberPassword, flags ); switch (result) { case NativeMethods.CredUIReturnCodes.NO_ERROR: usernameItem.Value = sbUserName.ToString(); passwordItem.Value = sbPassword.ToString(); break; case NativeMethods.CredUIReturnCodes.ERROR_CANCELLED: usernameItem.Value = null; passwordItem.Value = null; e.Cancel = true; break; } }
private string GetCacheKey(string uri, GitCredentialItem item) { return (uri ?? "") + ":" + item.Type + ":" + (item.PromptText ?? ""); }