Ejemplo n.º 1
0
        private void ReadAccountData()
        {
            Hashtable attrs = new Hashtable();

            attrs [KeyringItemNameAttr] = KeyringItemName;
            attrs [KeyringItemAppAttr]  = KeyringItemApp;

            try {
                Gnome.Keyring.ItemType type = Gnome.Keyring
                                              .ItemType.GenericSecret;
                Gnome.Keyring.ItemData [] items =
                    Gnome.Keyring.Ring.Find(
                        type, attrs);
                if (items.Length > 1)
                {
                    Log.Warning("More than one " + KeyringItemName + "found in keyring");
                }

                if (1 <= items.Length)
                {
                    Log.DebugFormat(KeyringItemName + " data found in " + "keyring");
                    attrs = items [0].Attributes;
                    username_entry.Text = (string)attrs [
                        KeyringItemUsernameAttr];
                    password_entry.Text = items [0].Secret;
                }
            } catch (Gnome.Keyring.KeyringException e) {
                Log.DebugFormat("Error while reading account data:\n" + e);
            }
        }
Ejemplo n.º 2
0
        private void ReadAccountData()
        {
            string new_username = string.Empty;
            string new_password = string.Empty;

            Hashtable attrs = new Hashtable();

            attrs [KeyringItemNameAttr] = KeyringItemName;
            attrs [KeyringItemAppAttr]  = KeyringItemApp;

            try {
                Gnome.Keyring.ItemType type = Gnome.Keyring
                                              .ItemType.GenericSecret;
                Gnome.Keyring.ItemData [] items =
                    Gnome.Keyring.Ring.Find(
                        type, attrs);
                if (1 < items.Length)
                {
                    Log.WarningFormat("More than one {0} "
                                      + " found in keyring",
                                      KeyringItemName);
                }

                if (1 <= items.Length)
                {
                    Log.DebugFormat("{0} data found in "
                                    + "keyring",
                                    KeyringItemName);
                    attrs        = items [0].Attributes;
                    new_username = (string)attrs [
                        KeyringItemUsernameAttr];
                    new_password = items [0].Secret;
                }
            } catch (Gnome.Keyring.KeyringException e) {
                Log.Exception("Error reading account data", e);
            }

            Username = new_username;
            Password = new_password;
        }
Ejemplo n.º 3
0
        private void WriteAccountData()
        {
            try {
                string keyring = Gnome.Keyring
                                 .Ring.GetDefaultKeyring();

                Hashtable attrs = new Hashtable();
                attrs [KeyringItemNameAttr] = KeyringItemName;
                attrs [KeyringItemAppAttr]  = KeyringItemApp;

                Gnome.Keyring.ItemType type = Gnome.Keyring
                                              .ItemType.GenericSecret;

                try {
                    Gnome.Keyring.ItemData [] items = Gnome
                                                      .Keyring.Ring.Find(
                        type,
                        attrs);

                    foreach (Gnome.Keyring.ItemData item
                             in items)
                    {
                        Gnome.Keyring.Ring.DeleteItem(
                            keyring,
                            item.ItemID);
                    }
                } catch (Gnome.Keyring.KeyringException e) {
                    Log.Exception("Error deleting old "
                                  + "account data", e);
                }

                attrs [KeyringItemUsernameAttr] = Username;

                Gnome.Keyring.Ring.CreateItem(keyring, type,
                                              KeyringItemName, attrs,
                                              Password, true);
            } catch (Gnome.Keyring.KeyringException e) {
                Log.Exception("Error writing account data", e);
            }
        }