manpagez: man pages & more
html files: libsecret-1
Home | html | info | man

Vala example: Lookup a password

Here's how to lookup a password in the running secret service, like gnome-keyring or ksecretservice.

Each stored password has a set of attributes which are used to lookup the password. If multiple passwords match the lookup attributes, then the one stored most recently is returned.

These examples use the example schema.

This first example looks up a password asynchronously, and is appropriate for GUI applications so that the UI does not block.

1
2
3
4
5
6
7
8
var attributes = new GLib.HashTable<string,string> ();
attributes["number"] = "8";
attributes["string"] = "eight";
attributes["even"] = "true";

Secret.password_lookupv.begin (example_schema, attributes, null, (obj, async_res) => {
    string password = Secret.password_lookup.end (async_res);
});

This next example looks up a password synchronously. The function call will block until the lookup completes. So this is appropriate for non GUI applications.

1
2
3
string password = Secret.password_lookup_sync (example_schema, attributes, null,
                                               "number", 9, "string", "nine", "even", false);
/* password will be null, if no matching password found */
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.