Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <wincred.h>
- #include <tchar.h>
- #pragma hdrstop
- void main ()
- {
- { //--- SAVE
- char* password = "brillant";
- DWORD cbCreds = 1 + strlen(password);
- CREDENTIALW cred = {0};
- cred.Type = CRED_TYPE_GENERIC;
- cred.TargetName = L"FOO/account";
- cred.CredentialBlobSize = cbCreds;
- cred.CredentialBlob = (LPBYTE) password;
- cred.Persist = CRED_PERSIST_LOCAL_MACHINE;
- cred.UserName = L"paula";
- BOOL ok = ::CredWriteW (&cred, 0);
- wprintf (L"CredWrite() - errno %dn", ok ? 0 : ::GetLastError());
- if (!ok) exit(1);
- }
- { //--- RETRIEVE
- PCREDENTIALW pcred;
- BOOL ok = ::CredReadW (L"FOO/account", CRED_TYPE_GENERIC, 0, &pcred);
- wprintf (L"CredRead() - errno %dn", ok ? 0 : ::GetLastError());
- if (!ok) exit(1);
- wprintf (L"Read username = '%s', password='%S' (%d bytes)n",
- pcred->UserName, (char*)pcred->CredentialBlob, pcred->CredentialBlobSize);
- // must free memory allocated by CredRead()!
- ::CredFree (pcred);
- }
- }
- [void][Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime]
- (new-object Windows.Security.Credentials.PasswordVault).RetrieveAll() | % { $_.RetrievePassword(); $_ }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement