Last active
August 10, 2016 11:09
-
-
Save vadz/4660956649e9ae6e9cd18ee07c9e7d35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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