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.

505 lines
13 KiB

  1. // PswdDlg.cpp -- PaSsWorD DiaLoG class definition
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. //
  8. #if defined(_UNICODE)
  9. #if !defined(UNICODE)
  10. #define UNICODE
  11. #endif //!UNICODE
  12. #endif //_UNICODE
  13. #if defined(UNICODE)
  14. #if !defined(_UNICODE)
  15. #define _UNICODE
  16. #endif //!_UNICODE
  17. #endif //UNICODE
  18. #include "stdafx.h"
  19. #include <scuOsExc.h>
  20. #include "slbCsp.h"
  21. #include "LoginId.h"
  22. #include "AccessTok.h"
  23. #include "PswdDlg.h"
  24. #include "PromptUser.h"
  25. #include "StResource.h"
  26. #include "CspProfile.h"
  27. using namespace ProviderProfile;
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. BEGIN_MESSAGE_MAP(CLogoDialog, CDialog)
  34. //{{AFX_MSG_MAP(CLogoDialog)
  35. ON_WM_PAINT()
  36. ON_WM_DESTROY()
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CLogoDialog dialog
  41. CLogoDialog::CLogoDialog(CWnd* pParent /*=NULL*/)
  42. : CDialog(),
  43. m_dcMem(),
  44. m_dcMask(),
  45. m_bmpLogo(),
  46. m_bmpMask(),
  47. m_hBmpOld(),
  48. m_hBmpOldM(),
  49. m_pt(0,0),
  50. m_size()
  51. {
  52. m_pParent = pParent;
  53. }
  54. ////////////////////////////////////////////////////////////////////////////
  55. // CLogoDialog message handlers
  56. BOOL CLogoDialog::OnInitDialog()
  57. {
  58. CBitmap * pBmpOld, * pBmpOldM;
  59. HINSTANCE oldHandle = NULL;
  60. BOOL fSuccess = TRUE;
  61. try {
  62. CDialog::OnInitDialog();
  63. // Load bitmap resource - remember to call DeleteObject when done.
  64. oldHandle = AfxGetResourceHandle();
  65. AfxSetResourceHandle(CspProfile::Instance().Resources());
  66. m_bmpLogo.LoadBitmap( MAKEINTRESOURCE( IDB_BITMAP_SLBLOGO ) );
  67. m_bmpMask.LoadBitmap( MAKEINTRESOURCE( IDB_BITMAP_SLBLOGO ) );
  68. // Get bitmap information
  69. m_bmpLogo.GetObject( sizeof(BITMAP), &m_bmInfo );
  70. m_size.cx = m_bmInfo.bmWidth;
  71. m_size.cy = m_bmInfo.bmHeight;
  72. // Get temporary DC for dialog - Will be released in dc destructor
  73. CClientDC dc(this);
  74. // Create compatible memory DC using the dialogs DC
  75. m_dcMem.CreateCompatibleDC( &dc );
  76. m_dcMask.CreateCompatibleDC( &dc );
  77. // Select logo bitmap into DC.
  78. // Get pointer to original bitmap
  79. // NOTE! This is temporary - save the handle instead
  80. pBmpOld = m_dcMem.SelectObject( &m_bmpLogo );
  81. SetBkColor(m_dcMem, RGB(255, 255, 255));
  82. m_dcMask.BitBlt (0, 0, m_size.cx, m_size.cy, &m_dcMem, 0, 0, SRCCOPY);
  83. pBmpOldM = m_dcMask.SelectObject( &m_bmpMask );
  84. m_hBmpOld = (HBITMAP) pBmpOld->GetSafeHandle();
  85. m_hBmpOldM = (HBITMAP) pBmpOldM->GetSafeHandle();
  86. }
  87. catch (...)
  88. {
  89. fSuccess = FALSE;
  90. }
  91. if (oldHandle)
  92. AfxSetResourceHandle(oldHandle);
  93. return fSuccess;
  94. }
  95. //***********************************************************************
  96. // CLogoDialog::OnPaint()
  97. //
  98. // Purpose:
  99. //
  100. // BitBlt() bitmap stored in compatible memory DC into dialogs
  101. // DC to display at hardcoded location.
  102. //
  103. // Parameters:
  104. //
  105. // None.
  106. //
  107. // Returns:
  108. //
  109. // None.
  110. //
  111. // Comments:
  112. //
  113. // History:
  114. //
  115. //***********************************************************************
  116. void CLogoDialog::OnPaint()
  117. {
  118. CPaintDC dc(this); // device context for painting
  119. // BitBlt logo bitmap onto dialog using transparancy masking
  120. dc.SetBkColor(RGB(255, 255, 255)); // 1s --> 0xFFFFFF
  121. dc.SetTextColor(RGB(0, 0, 0)); // 0s --> 0x000000
  122. // Do the real work.
  123. dc.BitBlt(m_pt.x, m_pt.y, m_size.cx, m_size.cy, &m_dcMem, 0, 0, SRCINVERT);
  124. dc.BitBlt(m_pt.x, m_pt.y, m_size.cx, m_size.cy, &m_dcMask, 0, 0, SRCAND);
  125. dc.BitBlt(m_pt.x, m_pt.y, m_size.cx, m_size.cy, &m_dcMem, 0, 0, SRCINVERT);
  126. /*
  127. * First two parameters are upper left position to place bitmap.
  128. * Third and fourth parameters are width and height to copy
  129. * (could be less than actual size of bitmap)
  130. * Sixth and seventh are position in memory dc to start from
  131. * SRCCOPY specifies copy.
  132. * See BitBlt documentation for more details.
  133. */
  134. // Do not call CDialog::OnPaint() for painting messages
  135. }
  136. //***********************************************************************
  137. // CLogoDialog::OnDestroy()
  138. //
  139. // Purpose:
  140. //
  141. // Select old bitmap back into memory DC before it is destroyed
  142. // when CLogoDialog object is.
  143. // DeleteObject() the bitmap which had been loaded.
  144. //
  145. // Parameters:
  146. //
  147. // None.
  148. //
  149. // Returns:
  150. //
  151. // None.
  152. //
  153. // Comments:
  154. //
  155. // History:
  156. //
  157. //
  158. void CLogoDialog::OnDestroy()
  159. {
  160. CDialog::OnDestroy();
  161. // Select old bitmap into memory dc (selecting out logo bitmap)
  162. // Need to create a temporary pointer to pass to do this
  163. if (m_hBmpOld && m_dcMem)
  164. m_dcMem.SelectObject(CBitmap::FromHandle(m_hBmpOld));
  165. if (m_hBmpOldM && m_dcMem)
  166. m_dcMask.SelectObject(CBitmap::FromHandle(m_hBmpOldM));
  167. // Need to DeleteObject() the bitmap that was loaded
  168. m_bmpLogo.DeleteObject();
  169. m_bmpMask.DeleteObject();
  170. // m_dcMem and m_dcMask destructor will handle rest of cleanup
  171. }
  172. /////////////////////////////////////////////////////////////////////////////
  173. // CPasswordDlg dialog
  174. CPasswordDlg::CPasswordDlg(CWnd* pParent /*=NULL*/)
  175. : CLogoDialog(pParent),
  176. m_szPassword(_T("")),
  177. m_szMessage(_T("")),
  178. m_fHexCode(FALSE),
  179. m_bChangePIN(FALSE),
  180. m_lid(User), // the default
  181. m_nPasswordSizeLimit(AccessToken::MaxPinLength)
  182. {
  183. m_pParent = pParent;
  184. m_pt.x = 144;
  185. m_pt.y = 88;
  186. }
  187. BEGIN_MESSAGE_MAP(CPasswordDlg, CLogoDialog)
  188. //{{AFX_MSG_MAP(CPasswordDlg)
  189. ON_BN_CLICKED(IDC_HEXCODE, OnClickHexCode)
  190. ON_BN_CLICKED(IDC_CHANGEPIN, OnChangePINAfterLogin)
  191. ON_WM_SHOWWINDOW()
  192. //}}AFX_MSG_MAP
  193. END_MESSAGE_MAP()
  194. void CPasswordDlg::DoDataExchange(CDataExchange* pDX)
  195. {
  196. CLogoDialog::DoDataExchange(pDX);
  197. //{{AFX_DATA_MAP(CPasswordDlg)
  198. DDX_Control(pDX, IDC_HEXCODE, m_ctlCheckHexCode);
  199. DDX_Control(pDX, IDC_CHANGEPIN, m_ctlCheckChangePIN);
  200. // DDX_Control(pDX, IDC_EDIT_VERNEWPIN, m_ctlVerifyNewPIN);
  201. // DDX_Control(pDX, IDC_EDIT_NEWPIN, m_ctlNewPIN);
  202. // DDX_Control(pDX, IDC_STATIC_VERNEWPIN, m_ctlVerifyPINLabel);
  203. // DDX_Control(pDX, IDC_STATIC_NEWPIN, m_ctlNewPINLabel);
  204. DDX_Text(pDX, IDC_PASSWORD, m_szPassword);
  205. DDV_MaxChars(pDX, m_szPassword, m_nPasswordSizeLimit);
  206. LPCTSTR pBuffer = (LPCTSTR) m_szMessage;
  207. if(!m_szMessage.IsEmpty())
  208. {
  209. DDX_Text(pDX, IDC_MESSAGE, (LPTSTR)pBuffer, m_szMessage.GetLength());
  210. }
  211. DDX_Check(pDX, IDC_CHANGEPIN, m_bChangePIN);
  212. // DDX_Text(pDX, IDC_EDIT_NEWPIN, m_csNewPIN);
  213. // DDX_Text(pDX, IDC_EDIT_VERNEWPIN, m_csVerifyNewPIN);
  214. //}}AFX_DATA_MAP
  215. }
  216. /////////////////////////////////////////////////////////////////////////////
  217. // CPasswordDlg message handlers
  218. BOOL CPasswordDlg::OnInitDialog()
  219. {
  220. CLogoDialog::OnInitDialog();
  221. switch (m_lid)
  222. {
  223. case User:
  224. // Give the user a chance to change the PIN
  225. m_ctlCheckChangePIN.ShowWindow(SW_SHOW);
  226. {
  227. m_szMessage = StringResource(IDS_ENTER_PIN).AsCString();
  228. }
  229. break;
  230. case Manufacturer:
  231. // Allow Hex string entry
  232. m_ctlCheckHexCode.ShowWindow(SW_SHOW);
  233. {
  234. m_szMessage = StringResource(IDS_ENTER_MANUFACTURER_KEY).AsCString();
  235. }
  236. break;
  237. case Administrator:
  238. // Allow Hex string entry
  239. m_ctlCheckHexCode.ShowWindow(SW_SHOW);
  240. {
  241. m_szMessage = StringResource(IDS_ENTER_ADMIN_KEY).AsCString();
  242. }
  243. break;
  244. default:
  245. break;
  246. };
  247. // Update GUI with changes
  248. UpdateData(FALSE);
  249. SetForegroundWindow();
  250. return TRUE; // return TRUE unless you set the focus to a control
  251. // EXCEPTION: OCX Property Pages should return FALSE
  252. }
  253. void CPasswordDlg::OnClickHexCode()
  254. {
  255. m_fHexCode = ~m_fHexCode;
  256. m_nPasswordSizeLimit = (m_fHexCode)
  257. ? AccessToken::MaxPinLength * 2
  258. : AccessToken::MaxPinLength;
  259. UpdateData(FALSE);
  260. }
  261. void CPasswordDlg::OnOK()
  262. {
  263. UpdateData();
  264. CString msg;
  265. bool fPrompt = true;
  266. if (m_fHexCode && m_szPassword.GetLength() != m_nPasswordSizeLimit)
  267. {
  268. msg.Format(m_fHexCode ?
  269. (LPCTSTR)StringResource(IDS_PIN_HEX_LIMIT).AsCString() :
  270. (LPCTSTR)StringResource(IDS_PIN_CHAR_LIMIT).AsCString(),
  271. m_nPasswordSizeLimit);
  272. }
  273. else if ((User == m_lid) && (0 == m_szPassword.GetLength()))
  274. {
  275. msg = (LPCTSTR)StringResource(IDS_MIN_PIN_LENGTH).AsCString();
  276. }
  277. else
  278. fPrompt = false;
  279. if (fPrompt)
  280. {
  281. HWND hWnd = m_pParent
  282. ? m_pParent->m_hWnd
  283. : NULL;
  284. int iResponse = PromptUser(hWnd, msg,
  285. MB_OK | MB_ICONERROR);
  286. if (IDCANCEL == iResponse)
  287. throw scu::OsException(ERROR_CANCELLED);
  288. }
  289. else
  290. CLogoDialog::OnOK();
  291. }
  292. void CPasswordDlg::OnChangePINAfterLogin()
  293. {
  294. UpdateData(); // set m_bChangePIN
  295. int nShowWindow = (m_bChangePIN) ? SW_SHOW : SW_HIDE;
  296. /*
  297. m_ctlVerifyNewPIN.ShowWindow(nShowWindow);
  298. m_ctlNewPIN.ShowWindow(nShowWindow);
  299. m_ctlVerifyPINLabel.ShowWindow(nShowWindow);
  300. m_ctlNewPINLabel.ShowWindow(nShowWindow);
  301. */
  302. }
  303. void CPasswordDlg::OnShowWindow(BOOL bShow, UINT nStatus)
  304. {
  305. CLogoDialog::OnShowWindow(bShow, nStatus);
  306. }
  307. /////////////////////////////////////////////////////////////////////////////
  308. // CChangePINDlg dialog
  309. CChangePINDlg::CChangePINDlg(CWnd* pParent /*=NULL*/)
  310. : CLogoDialog(pParent),
  311. m_csOldPIN(_T("")),
  312. m_csNewPIN(_T("")),
  313. m_csVerifyNewPIN(_T(""))
  314. {
  315. m_pParent = pParent;
  316. m_pt.x = 144; // 132;
  317. m_pt.y = 75; //104;
  318. }
  319. void CChangePINDlg::DoDataExchange(CDataExchange* pDX)
  320. {
  321. CLogoDialog::DoDataExchange(pDX);
  322. //{{AFX_DATA_MAP(CChangePINDlg)
  323. DDX_Control(pDX, IDC_STATIC_CONFIRM_OLDPIN_LABEL, m_ctlConfirmOldPINLabel);
  324. DDX_Control(pDX, IDC_EDIT_OLDPIN, m_ctlOldPIN);
  325. DDX_Text(pDX, IDC_EDIT_OLDPIN, m_csOldPIN);
  326. DDV_MaxChars(pDX, m_csOldPIN, AccessToken::MaxPinLength);
  327. DDX_Text(pDX, IDC_EDIT_NEWPIN, m_csNewPIN);
  328. DDV_MaxChars(pDX, m_csNewPIN, AccessToken::MaxPinLength);
  329. DDX_Text(pDX, IDC_EDIT_VERNEWPIN, m_csVerifyNewPIN);
  330. DDV_MaxChars(pDX, m_csVerifyNewPIN, AccessToken::MaxPinLength);
  331. //}}AFX_DATA_MAP
  332. }
  333. BEGIN_MESSAGE_MAP(CChangePINDlg, CLogoDialog)
  334. //{{AFX_MSG_MAP(CChangePINDlg)
  335. ON_WM_SHOWWINDOW()
  336. //}}AFX_MSG_MAP
  337. END_MESSAGE_MAP()
  338. /////////////////////////////////////////////////////////////////////////////
  339. // CChangePINDlg message handlers
  340. // The purpose of the Change PIN dialog is for changing User Pins.
  341. // It may be invoked after having already authenticated, or prior
  342. // to authentication. In the former case it is recommended that the
  343. // caller will have set the m_csOldPIN data member prior to calling
  344. // DoModal(). This is so the user will not have to reenter a PIN
  345. // that has previously been entered.
  346. BOOL CChangePINDlg::OnInitDialog()
  347. {
  348. CLogoDialog::OnInitDialog();
  349. SetForegroundWindow();
  350. return TRUE; // return TRUE unless you set the focus to a control
  351. // EXCEPTION: OCX Property Pages should return FALSE
  352. }
  353. void CChangePINDlg::OnOK()
  354. {
  355. UpdateData();
  356. UINT uiMsgId;
  357. bool fMsgIdSet = false;
  358. // Verify that the New PIN contains only ASCII characters
  359. if(!StringResource::IsASCII((LPCTSTR)m_csNewPIN))
  360. {
  361. uiMsgId = IDS_PIN_NONASCII;
  362. fMsgIdSet = true;
  363. }
  364. // Verify that the New PIN and Verify PIN are the same
  365. else if (m_csNewPIN != m_csVerifyNewPIN)
  366. {
  367. uiMsgId = IDS_PIN_VER_NO_MATCH;
  368. fMsgIdSet = true;
  369. }
  370. // Verify that the length of the new PIN is >= 1
  371. else if (0 == m_csNewPIN.GetLength())
  372. {
  373. uiMsgId = IDS_MIN_NEW_PIN_LENGTH;
  374. fMsgIdSet = true;
  375. }
  376. // Verify that the length of the old PIN is >= 1
  377. else if (0 == m_csOldPIN.GetLength())
  378. {
  379. uiMsgId = IDS_MIN_OLD_PIN_LENGTH;
  380. fMsgIdSet = true;
  381. }
  382. if (fMsgIdSet)
  383. {
  384. HWND hWnd = m_pParent
  385. ? m_pParent->m_hWnd
  386. : NULL;
  387. int iResponse = PromptUser(hWnd, uiMsgId,
  388. MB_OK | MB_ICONSTOP);
  389. if (IDCANCEL == iResponse)
  390. throw scu::OsException(ERROR_CANCELLED);
  391. }
  392. else
  393. CLogoDialog::OnOK();
  394. }
  395. void CChangePINDlg::OnShowWindow(BOOL bShow, UINT nStatus)
  396. {
  397. CLogoDialog::OnShowWindow(bShow, nStatus);
  398. // if the caller placed something in the m_csOldPIN
  399. // prior to DoModal'ing, then don't show that control,
  400. // so that the user won't accidentally erase the preset,
  401. // current PIN
  402. if (m_csOldPIN.GetLength())
  403. {
  404. m_ctlOldPIN.ShowWindow(FALSE);
  405. m_ctlConfirmOldPINLabel.ShowWindow(FALSE);
  406. }
  407. }