Example #1
0
        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);
        }
Example #2
0
        static bool TryGetPassphrase(URIish uri, CredentialItem[] items, out CredentialItem.StringType passphraseItem)
        {
            var actualUrl  = new Uri(uri.ToString());
            var passphrase = (CredentialItem.StringType)items.FirstOrDefault(i => i is CredentialItem.StringType);

            if (items.Length == 1 && passphrase != null)
            {
                passphraseItem = passphrase;

                var passphraseValue = PasswordService.GetWebPassword(actualUrl);
                if (passphraseValue != null)
                {
                    passphrase.SetValue(passphraseValue);
                    return(true);
                }
            }
            else
            {
                passphraseItem = null;
            }

            return(false);
        }