Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.5 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. //
  3. // credentials dialog
  4. //
  5. // 03-31-98 sburns
  6. // 10-05-00 jonn changed to CredUIGetPassword
  7. // 12-18-00 jonn 260752: changed to CredUIPromptForCredentials
  8. #include "headers.hxx"
  9. #include "cred.hpp"
  10. #include "resource.h"
  11. #include <wincred.h> // CredUIPromptForCredentials
  12. // JonN 10/5/00 188220
  13. // JonN 12/18/00 260752: changed to CredUIPromptForCredentials
  14. bool RetrieveCredentials(
  15. HWND hwndParent,
  16. unsigned promptResID,
  17. String& username,
  18. String& password)
  19. {
  20. ASSERT( NULL != hwndParent && 0 != promptResID );
  21. String strMessageText = String::load(promptResID);
  22. String strAppTitle = String::load(IDS_APP_TITLE);
  23. CREDUI_INFO uiInfo;
  24. ::ZeroMemory( &uiInfo, sizeof(uiInfo) );
  25. uiInfo.cbSize = sizeof(uiInfo);
  26. uiInfo.hwndParent = hwndParent;
  27. uiInfo.pszMessageText = strMessageText.c_str();
  28. uiInfo.pszCaptionText = strAppTitle.c_str();
  29. TCHAR achUserName[CREDUI_MAX_USERNAME_LENGTH];
  30. TCHAR achPassword[CREDUI_MAX_PASSWORD_LENGTH];
  31. ::ZeroMemory(&achUserName,sizeof(achUserName));
  32. ::ZeroMemory(&achPassword,sizeof(achPassword));
  33. DWORD dwErr = CredUIPromptForCredentials(
  34. &uiInfo,
  35. NULL,
  36. NULL,
  37. NO_ERROR,
  38. achUserName,
  39. CREDUI_MAX_USERNAME_LENGTH,
  40. achPassword,
  41. CREDUI_MAX_PASSWORD_LENGTH,
  42. NULL,
  43. CREDUI_FLAGS_DO_NOT_PERSIST | CREDUI_FLAGS_GENERIC_CREDENTIALS
  44. );
  45. if (NO_ERROR != dwErr) // e.g. ERROR_CANCELLED
  46. return false;
  47. username = achUserName;
  48. password = achPassword;
  49. return true;
  50. }