Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <windows.h>
  2. #include <wincred.h>
  3. #include <tchar.h>
  4. #pragma hdrstop
  5.  
  6. void main ()
  7. {
  8. { //--- SAVE
  9. char* password = "brillant";
  10. DWORD cbCreds = 1 + strlen(password);
  11.  
  12. CREDENTIALW cred = {0};
  13. cred.Type = CRED_TYPE_GENERIC;
  14. cred.TargetName = L"FOO/account";
  15. cred.CredentialBlobSize = cbCreds;
  16. cred.CredentialBlob = (LPBYTE) password;
  17. cred.Persist = CRED_PERSIST_LOCAL_MACHINE;
  18. cred.UserName = L"paula";
  19.  
  20. BOOL ok = ::CredWriteW (&cred, 0);
  21. wprintf (L"CredWrite() - errno %dn", ok ? 0 : ::GetLastError());
  22. if (!ok) exit(1);
  23. }
  24. { //--- RETRIEVE
  25. PCREDENTIALW pcred;
  26. BOOL ok = ::CredReadW (L"FOO/account", CRED_TYPE_GENERIC, 0, &pcred);
  27. wprintf (L"CredRead() - errno %dn", ok ? 0 : ::GetLastError());
  28. if (!ok) exit(1);
  29. wprintf (L"Read username = '%s', password='%S' (%d bytes)n",
  30. pcred->UserName, (char*)pcred->CredentialBlob, pcred->CredentialBlobSize);
  31. // must free memory allocated by CredRead()!
  32. ::CredFree (pcred);
  33. }
  34. }
  35.  
  36. [void][Windows.Security.Credentials.PasswordVault,Windows.Security.Credentials,ContentType=WindowsRuntime]
  37. (new-object Windows.Security.Credentials.PasswordVault).RetrieveAll() | % { $_.RetrievePassword(); $_ }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement