Skip to content

Instantly share code, notes, and snippets.

@saostad
Last active February 26, 2021 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saostad/0da32d31dbfa2e2b81716eba4dbbb03b to your computer and use it in GitHub Desktop.
Save saostad/0da32d31dbfa2e2b81716eba4dbbb03b to your computer and use it in GitHub Desktop.
read_from_windows_credential_manager.cpp
#include <Windows.h>
#include <WinCred.h>
#include <iostream>
using namespace std;
main()
{
PCREDENTIALA cred;
LPCSTR cred_name = "test_cred";
const bool result = ::CredReadA(cred_name, 1, 0, &cred);
auto blobSize = cred->CredentialBlobSize;
if (result)
{
wchar_t const *const passwordOut = (wchar_t const *const)cred->CredentialBlob;
cout << cred->UserName << endl;
wcout << passwordOut << endl;
}
else
{
wcout << GetLastError();
}
::CredFree(cred);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment