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.

203 lines
6.2 KiB

  1. /****************************************************************************\
  2. *
  3. * chngdlg.h
  4. *
  5. * Created: William Taylor (wtaylor) 01/22/01
  6. *
  7. * MS Ratings Change Password Dialog
  8. *
  9. \****************************************************************************/
  10. #ifndef CHANGE_PASSWORD_DIALOG_H
  11. #define CHANGE_PASSWORD_DIALOG_H
  12. #include "basedlg.h" // CBaseDialog
  13. #include "hint.h" // CHint
  14. #include <contxids.h> // Help Context ID's
  15. #include <mluisupp.h> // SHWinHelpOnDemandWrap() and MLLoadStringA()
  16. static DWORD aIdsChangePassword[] = {
  17. IDC_STATIC5, IDH_IGNORE,
  18. IDC_STATIC1, IDH_RATINGS_CHANGE_PASSWORD_OLD,
  19. IDC_OLD_PASSWORD, IDH_RATINGS_CHANGE_PASSWORD_OLD,
  20. IDC_STATIC2, IDH_RATINGS_CHANGE_PASSWORD_NEW,
  21. IDC_PASSWORD, IDH_RATINGS_CHANGE_PASSWORD_NEW,
  22. IDC_STATIC4, IDH_RATINGS_SUPERVISOR_CREATE_PASSWORD,
  23. IDC_CREATE_PASSWORD, IDH_RATINGS_SUPERVISOR_CREATE_PASSWORD,
  24. IDC_STATIC3, IDH_RATINGS_CHANGE_PASSWORD_CONFIRM,
  25. IDC_CONFIRM_PASSWORD, IDH_RATINGS_CHANGE_PASSWORD_CONFIRM,
  26. IDC_OLD_HINT_LABEL, IDH_RATINGS_DISPLAY_PW_HINT,
  27. IDC_OLD_HINT_TEXT, IDH_RATINGS_DISPLAY_PW_HINT,
  28. IDC_HINT_TEXT, IDH_IGNORE,
  29. IDC_HINT_LABEL, IDH_RATINGS_ENTER_PW_HINT,
  30. IDC_HINT_EDIT, IDH_RATINGS_ENTER_PW_HINT,
  31. 0,0
  32. };
  33. template <WORD t_wDlgTemplateID>
  34. class CChangePasswordDialog: public CBaseDialog<CChangePasswordDialog>
  35. {
  36. public:
  37. enum { IDD = t_wDlgTemplateID };
  38. public:
  39. CChangePasswordDialog() { /* Add Construction Here */ }
  40. public:
  41. typedef CChangePasswordDialog thisClass;
  42. typedef CBaseDialog<thisClass> baseClass;
  43. BEGIN_MSG_MAP(thisClass)
  44. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  45. COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
  46. COMMAND_ID_HANDLER(IDOK, OnOK)
  47. MESSAGE_HANDLER(WM_HELP, OnHelp)
  48. MESSAGE_HANDLER(WM_CONTEXTMENU, OnContextMenu)
  49. CHAIN_MSG_MAP(baseClass)
  50. END_MSG_MAP()
  51. protected:
  52. LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  53. {
  54. if(GetDlgItem(IDC_OLD_PASSWORD)!=NULL)
  55. {
  56. SendDlgItemMessage(IDC_OLD_PASSWORD,EM_SETLIMITTEXT,(WPARAM) RATINGS_MAX_PASSWORD_LENGTH,(LPARAM) 0);
  57. }
  58. if(GetDlgItem(IDC_PASSWORD)!=NULL)
  59. {
  60. SendDlgItemMessage(IDC_PASSWORD,EM_SETLIMITTEXT,(WPARAM) RATINGS_MAX_PASSWORD_LENGTH,(LPARAM) 0);
  61. }
  62. if(GetDlgItem(IDC_CONFIRM_PASSWORD)!=NULL)
  63. {
  64. SendDlgItemMessage(IDC_CONFIRM_PASSWORD,EM_SETLIMITTEXT,(WPARAM) RATINGS_MAX_PASSWORD_LENGTH,(LPARAM) 0);
  65. }
  66. if(GetDlgItem(IDC_CREATE_PASSWORD)!=NULL)
  67. {
  68. SendDlgItemMessage(IDC_CREATE_PASSWORD,EM_SETLIMITTEXT,(WPARAM) RATINGS_MAX_PASSWORD_LENGTH,(LPARAM) 0);
  69. }
  70. // Display previously created hint (if one exists).
  71. {
  72. CHint oldHint( m_hWnd, IDC_OLD_HINT_TEXT );
  73. oldHint.DisplayHint();
  74. }
  75. // Set the length of the new hint.
  76. {
  77. CHint newHint( m_hWnd, IDC_HINT_EDIT );
  78. newHint.InitHint();
  79. }
  80. bHandled = FALSE;
  81. return 1L; // Let the system set the focus
  82. }
  83. LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  84. {
  85. EndDialog(FALSE);
  86. return 0L;
  87. }
  88. LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  89. {
  90. CHAR pszPassword[MAXPATHLEN];
  91. CHAR pszTempPassword[MAXPATHLEN];
  92. CHAR *p = NULL;
  93. HRESULT hRet;
  94. HWND hwndPassword;
  95. int iPasswordCtrl;
  96. HWND hDlg = m_hWnd;
  97. iPasswordCtrl = IDC_PASSWORD;
  98. hwndPassword = ::GetDlgItem( hDlg, iPasswordCtrl );
  99. if (hwndPassword == NULL)
  100. {
  101. iPasswordCtrl = IDC_CREATE_PASSWORD;
  102. hwndPassword = ::GetDlgItem( hDlg, iPasswordCtrl );
  103. }
  104. ASSERT( hwndPassword );
  105. ::GetWindowText(hwndPassword, pszPassword, sizeof(pszPassword));
  106. GetDlgItemText(IDC_CONFIRM_PASSWORD, pszTempPassword, sizeof(pszTempPassword));
  107. /* if they've typed just the first password but not the
  108. * second, let Enter take them to the second field
  109. */
  110. if (*pszPassword && !*pszTempPassword && GetFocus() == hwndPassword)
  111. {
  112. SetErrorControl( IDC_CONFIRM_PASSWORD );
  113. return 0L;
  114. }
  115. if (strcmpf(pszPassword, pszTempPassword))
  116. {
  117. MyMessageBox(hDlg, IDS_NO_MATCH, IDS_GENERIC, MB_OK);
  118. SetErrorControl( IDC_CONFIRM_PASSWORD );
  119. return 0L;
  120. }
  121. if (*pszPassword=='\0')
  122. {
  123. MyMessageBox(hDlg, IDS_NO_NULL_PASSWORD, IDS_GENERIC, MB_OK);
  124. SetErrorControl( iPasswordCtrl );
  125. return 0L;
  126. }
  127. if ( SUCCEEDED( VerifySupervisorPassword() ) )
  128. {
  129. GetDlgItemText(IDC_OLD_PASSWORD, pszTempPassword, sizeof(pszTempPassword));
  130. p = pszTempPassword;
  131. }
  132. // Verify the Newly Added Hint.
  133. CHint newHint( hDlg, IDC_HINT_EDIT );
  134. if ( ! newHint.VerifyHint() )
  135. {
  136. TraceMsg( TF_ALWAYS, "CChangePasswordDialog::OnOK() - User requested to fill in hint." );
  137. return 0L;
  138. }
  139. hRet = ChangeSupervisorPassword(p, pszPassword);
  140. if (SUCCEEDED(hRet))
  141. {
  142. // Save the Newly Added Hint.
  143. newHint.SaveHint();
  144. EndDialog(TRUE);
  145. }
  146. else
  147. {
  148. MyMessageBox(hDlg, IDS_BADPASSWORD, IDS_GENERIC, MB_OK|MB_ICONERROR);
  149. SetErrorControl( IDC_OLD_PASSWORD );
  150. }
  151. return 0L;
  152. }
  153. LRESULT OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  154. {
  155. SHWinHelpOnDemandWrap((HWND)((LPHELPINFO)lParam)->hItemHandle, ::szHelpFile,
  156. HELP_WM_HELP, (DWORD_PTR)(LPSTR)aIdsChangePassword);
  157. return 0L;
  158. }
  159. LRESULT OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  160. {
  161. SHWinHelpOnDemandWrap((HWND)wParam, ::szHelpFile, HELP_CONTEXTMENU,
  162. (DWORD_PTR)(LPVOID)aIdsChangePassword);
  163. return 0L;
  164. }
  165. };
  166. #endif