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.

156 lines
3.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-2001.
  5. //
  6. // File: Password.cpp
  7. //
  8. // Contents:
  9. //
  10. //----------------------------------------------------------------------------\
  11. // Password.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "Password.h"
  15. #ifdef _DEBUG
  16. #ifndef ALPHA
  17. #define new DEBUG_NEW
  18. #endif
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CPassword dialog
  24. /*
  25. // This dialog is used by EFS Recovery agent export key code, which is
  26. // currently commented out.
  27. CPassword::CPassword(CWnd* pParent)
  28. : CHelpDialog(CPassword::IDD, pParent)
  29. {
  30. //{{AFX_DATA_INIT(CPassword)
  31. m_strPassword1 = _T("");
  32. m_strPassword2 = _T("");
  33. //}}AFX_DATA_INIT
  34. }
  35. void CPassword::DoDataExchange(CDataExchange* pDX)
  36. {
  37. CHelpDialog::DoDataExchange(pDX);
  38. //{{AFX_DATA_MAP(CPassword)
  39. DDX_Control(pDX, IDC_PASSWORD1, m_password1Edit);
  40. DDX_Text(pDX, IDC_PASSWORD1, m_strPassword1);
  41. DDX_Text(pDX, IDC_PASSWORD2, m_strPassword2);
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CPassword, CHelpDialog)
  45. //{{AFX_MSG_MAP(CPassword)
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CPassword message handlers
  50. LPCWSTR CPassword::GetPassword() const
  51. {
  52. return (LPCWSTR) m_strPassword1;
  53. }
  54. void CPassword::OnOK()
  55. {
  56. VERIFY (UpdateData (TRUE));
  57. if ( m_strPassword1 != m_strPassword2 )
  58. {
  59. CString caption;
  60. CString text;
  61. CThemeContextActivator activator;
  62. VERIFY (caption.LoadString (IDS_SET_PASSWORD));
  63. VERIFY (text.LoadString (IDS_PASSWORDS_DONT_MATCH));
  64. MessageBox (text, caption, MB_OK);
  65. ClearPasswords ();
  66. VERIFY (UpdateData (FALSE));
  67. m_password1Edit.SetFocus ();
  68. }
  69. else
  70. CHelpDialog::OnOK();
  71. }
  72. void CPassword::OnCancel()
  73. {
  74. CString caption;
  75. CString text;
  76. CThemeContextActivator activator;
  77. VERIFY (caption.LoadString (IDS_SET_PASSWORD));
  78. VERIFY (text.LoadString (IDS_CANCEL_NO_CREATE_PFX));
  79. if ( IDYES == MessageBox (text, caption, MB_YESNO) )
  80. CHelpDialog::OnCancel();
  81. }
  82. CPassword::~CPassword()
  83. {
  84. // Zero out memory before freeing to protect password
  85. ClearPasswords ();
  86. }
  87. BOOL CPassword::OnInitDialog()
  88. {
  89. CHelpDialog::OnInitDialog();
  90. m_password1Edit.SetFocus ();
  91. return FALSE; // return TRUE unless you set the focus to a control
  92. // EXCEPTION: OCX Property Pages should return FALSE
  93. }
  94. void CPassword::ClearPasswords()
  95. {
  96. size_t len = m_strPassword1.GetLength ();
  97. LPWSTR pstr = m_strPassword1.GetBuffer ((int) len);
  98. if ( pstr )
  99. {
  100. memset (pstr, 0, len * sizeof (TCHAR));
  101. }
  102. m_strPassword1.ReleaseBuffer ();
  103. len = m_strPassword2.GetLength ();
  104. pstr = m_strPassword2.GetBuffer ((int) len);
  105. if ( pstr )
  106. {
  107. memset (pstr, 0, len * sizeof (TCHAR));
  108. }
  109. m_strPassword2.ReleaseBuffer ();
  110. }
  111. void CPassword::DoContextHelp (HWND hWndControl)
  112. {
  113. _TRACE (1, L"Entering CPassword::DoContextHelp\n");
  114. static const DWORD help_map[] =
  115. {
  116. IDC_PASSWORD1, IDH_PASSWORD_PASSWORD1,
  117. IDC_PASSWORD2, IDH_PASSWORD_PASSWORD2,
  118. 0, 0
  119. };
  120. // Display context help for a control
  121. if ( !::WinHelp (
  122. hWndControl,
  123. GetF1HelpFilename(),
  124. HELP_WM_HELP,
  125. (DWORD_PTR) help_map) )
  126. {
  127. _TRACE (0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  128. }
  129. _TRACE (-1, L"Leaving CPassword::DoContextHelp\n");
  130. }
  131. */