Version: 3.1.1
wxSecretStore Class Reference

#include <wx/secretstore.h>

Detailed Description

A collection of secrets, sometimes called a key chain.

This class provides access to the secrets stored in the OS-provided facility, e.g. credentials manager under MSW, keychain under OS X or Freedesktop-compliant password storage mechanism such as GNOME keyring under Unix systems.

Currently only the access to the default keychain/ring is provided using GetDefault() method, support for other ones could be added in the future. After calling this method just call Save() to store a password entered by user and then call Load() to retrieve it during next program execution. See Secret Store Sample for an example of using this class.

The service parameter of the methods in this class should describe the purpose of the password and be unique to your program, e.g. it could be "MyCompany/MyProgram/SomeServer". Note that the server name must be included in the string to allow storing passwords for more than one server.

Notice that this class is always available under MSW (except when using MinGW32 which doesn't provide the required wincred.h header) and OS X but requires libsecret (see under Unix and may not be compiled in if it wasn't found. You can check wxUSE_SECRETSTORE to test for this. Moreover, retrieving the default secret store may also fail under Unix during run-time if the desktop environment doesn't provide one, so don't forget to call IsOk() to check for this too.

Library:  wxBase
Category:  Miscellaneous

Public Member Functions

bool IsOk () const
 Check if this object is valid. More...
bool Save (const wxString &service, const wxString &user, const wxSecretValue &secret)
 Store a secret. More...
wxSecretValue Load (const wxString &service, const wxString &user) const
 Look up a secret. More...
bool Delete (const wxString &service, const wxString &user)
 Delete a previously stored secret. More...

Static Public Member Functions

static wxSecretStore GetDefault ()
 Returns the default secrets collection to use. More...

Member Function Documentation

bool wxSecretStore::Delete ( const wxString service,
const wxString user 

Delete a previously stored secret.

If there is more than one matching secret, all of them are deleted.

If any secrets were deleted, returns true. Otherwise returns false and logs an error if any error other than not finding any matching secrets occurred.

static wxSecretStore wxSecretStore::GetDefault ( )

Returns the default secrets collection to use.

Call IsOk() on the returned object to check if this method succeeded.

bool wxSecretStore::IsOk ( ) const

Check if this object is valid.

wxSecretValue wxSecretStore::Load ( const wxString service,
const wxString user 
) const

Look up a secret.

If no such secret is found, an empty value is returned, but no error is logged (however an error may still be logged if some other error occurs). If more than one secret matching the parameters exist, only one arbitrarily chosen of them is returned (notice that it's impossible to get into such situation using this API only).

bool wxSecretStore::Save ( const wxString service,
const wxString user,
const wxSecretValue secret 

Store a secret.

The service name should be user readable and unique.

If a secret with the same service name and user already exists, it will be overwritten with the new value.

Returns false after logging an error message if an error occurs, otherwise returns true indicating that the secret has been stored and can be retrieved by calling Load() later.