Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Stores the credential.
        /// </summary>
        /// <returns><c>true</c>, if credential was stored, <c>false</c> otherwise save password in Uri (unsecure)</returns>
        /// <param name="url">URL.</param>
        /// <param name="password">Password.</param>
        public static void StoreCredential(Uri url, string password)
        {
            //Use Password Service for Mac and Windows
            if (Platform.IsMac || Platform.IsWindows)
            {
                PasswordService.AddWebPassword(url, password);
            }
            else //If Linux
            {
#if DBus
                if (IsRunningKDE)
                {
                    SaveToKWallet(url, password);//Use KDE Wallet should write code for Gnome Keyring.
                }
#endif
            }
        }