Skip to content

Instantly share code, notes, and snippets.

@vadz
Last active August 10, 2016 11:09
Show Gist options
  • Save vadz/4660956649e9ae6e9cd18ee07c9e7d35 to your computer and use it in GitHub Desktop.
Save vadz/4660956649e9ae6e9cd18ee07c9e7d35 to your computer and use it in GitHub Desktop.
#include <wx/secretstore.h>
void DoSomethingRequiringAPassword(const wxString& username)
{
wxSecretStore store = wxSecretStore::GetDefault();
if ( !store.IsOk() ) {
// Complain about not being able to store the password securely
...
return;
}
// This is a free-form string which should be reasonably unique.
const char* UNIQUE_SERVICE_NAME = "com.mycompany.myproject/database"
wxSecretValue secret = store.Load(UNIQUE_SERVICE_NAME, username);
if ( !secret.IsOk() ) {
const wxString password = AskUserForPassword(username);
// Use the password, confirming that it is correct
...
if ( wantsToSaveIt ) {
if ( !store.Save(UNIQUE_SERVICE_NAME, username, secret) ) {
// Warn about failing to save the password
...
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment