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

C example: Remove a password

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

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

These examples use the example schema.

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
static void
on_password_cleared (GObject *source,
                     GAsyncResult *result,
                     gpointer unused)
 {
    GError *error = NULL;

    gboolean removed = secret_password_clear_finish (result, &error);

    if (error != NULL) {
        /* ... handle the failure here */
        g_error_free (error);

    } else {
        /* removed will be TRUE if a password was removed */
    }
}

/*
 * The variable argument list is the attributes used to later
 * lookup the password. These attributes must conform to the schema.
 */
secret_password_clear (EXAMPLE_SCHEMA, NULL, on_password_cleard, NULL,
                       "string", "nine",
                       "even", FALSE,
                       NULL);

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
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
GError *error = NULL;

/*
 * The variable argument list is the attributes used to later
 * lookup the password. These attributes must conform to the schema.
 */
gboolean removed = secret_password_clear_sync (EXAMPLE_SCHEMA, NULL, &error,
                                               "string", "nine",
                                               "even", FALSE,
                                               NULL);

if (error != NULL) {
    /* ... handle the failure here */
    g_error_free (error);

} else {
    /* removed will be TRUE if a password was removed */
}
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.