static bool TryGetUsernamePassword(URIish uri, CredentialItem[] items, out CredentialItem.Password passwordItem) { var actualUrl = new Uri(uri.ToString()); var username = (CredentialItem.Username)items.FirstOrDefault(i => i is CredentialItem.Username); var password = (CredentialItem.Password)items.FirstOrDefault(i => i is CredentialItem.Password); if (items.Length == 2 && username != null && password != null) { passwordItem = password; var passwordValue = PasswordService.GetWebPassword(actualUrl); if (passwordValue != null) { username.SetValue(actualUrl.UserInfo); password.SetValueNoCopy(passwordValue.ToArray()); return(true); } } else { passwordItem = null; } return(false); }
public override bool Get(URIish uri, params CredentialItem[] items) { bool result = false; CredentialItem.Password passwordItem = null; CredentialItem.StringType passphraseItem = null; // We always need to run the TryGet* methods as we need the passphraseItem/passwordItem populated even // if the password store contains an invalid password/no password if (TryGetUsernamePassword(uri, items, out passwordItem) || TryGetPassphrase(uri, items, out passphraseItem)) { // If the password store has a password and we already tried using it, it could be incorrect. // If this happens, do not return true and ask the user for a new password. if (!HasReset) { return(true); } } DispatchService.GuiSyncDispatch(delegate { CredentialsDialog dlg = new CredentialsDialog(uri, items); try { result = MessageService.ShowCustomDialog(dlg) == (int)Gtk.ResponseType.Ok; } finally { dlg.Destroy(); } }); HasReset = false; if (result) { if (passwordItem != null) { PasswordService.AddWebPassword(new Uri(uri.ToString()), new string (passwordItem.GetValue())); } else if (passphraseItem != null) { PasswordService.AddWebPassword(new Uri(uri.ToString()), passphraseItem.GetValue()); } } return(result); }