Leaked source code of windows server 2003
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.

89 lines
2.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 2002
  6. //
  7. // File: credobj.cpp
  8. //
  9. // History: 2002/03/29 artm Separated from editor.cpp.
  10. // Reimplemented password storage to use data
  11. // protection API.
  12. //
  13. //--------------------------------------------------------------------------
  14. #include "pch.h"
  15. #include "credobj.h"
  16. #include <strsafe.h>
  17. CCredentialObject::CCredentialObject(void)
  18. : m_sUsername(_T("")),
  19. m_password(),
  20. m_bUseCredentials(FALSE)
  21. {
  22. }
  23. CCredentialObject::CCredentialObject(const CCredentialObject* pCredObject)
  24. : m_sUsername(_T("")),
  25. m_password(),
  26. m_bUseCredentials(FALSE)
  27. {
  28. if(NULL != pCredObject)
  29. {
  30. m_sUsername = pCredObject->m_sUsername;
  31. m_password = pCredObject->m_password;
  32. m_bUseCredentials = pCredObject->m_bUseCredentials;
  33. // This should never happen, but doesn't hurt to be
  34. // paranoid.
  35. ASSERT(m_password.GetLength() <= MAX_PASSWORD_LENGTH);
  36. }
  37. }
  38. CCredentialObject::~CCredentialObject(void)
  39. {
  40. }
  41. //
  42. // CCredentialObject::SetPasswordFromHwnd:
  43. //
  44. // Reads the text from hWnd and sets the password for this
  45. // credential object. If the password is longer than
  46. // MAX_PASSWORD_LENGTH characters the function returns
  47. // ERROR_INVALID_PARAMETER.
  48. //
  49. // History:
  50. // 2002/04/01 artm Changed implementation to not use RtlRunDecodeUnicodeString().
  51. // Instead, uses data protection API.
  52. //
  53. HRESULT CCredentialObject::SetPasswordFromHwnd(HWND parentDialog, int itemResID)
  54. {
  55. HRESULT err = S_OK;
  56. EncryptedString newPwd;
  57. // Read the new password from the dialog window.
  58. err = GetEncryptedDlgItemText(
  59. parentDialog,
  60. itemResID,
  61. newPwd);
  62. if (SUCCEEDED(err))
  63. {
  64. if (newPwd.GetLength() <= MAX_PASSWORD_LENGTH)
  65. {
  66. m_password = newPwd;
  67. }
  68. else
  69. {
  70. err = ERROR_INVALID_PARAMETER;
  71. }
  72. }
  73. return err;
  74. }