Develop and Download Open Source Software

Browse CVS Repository

Contents of /tombo/Tombo/Src/PasswordDialog.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Fri Sep 30 15:29:08 2005 UTC (18 years, 6 months ago) by hirami
Branch: MAIN
CVS Tags: Tombo_2_0a3, Tombo_1_17_1, B191, B192, B193, B194, B196, B197, B198, B199, B200, B201, B202, B203, B205, B206, B207, B208, B189, B188, B213, B212, B211, B217, B216, B215, B214, B219, B218, Tombo_2_0b2, Tombo_2_0b3, Tombo_2_0b1, Tombo_2_0b4, B228, B229, B226, B227, B224, B225, B222, B223, B220, B221, SNAPSHOT20051220, B231, B230, Tombo_1_15, Tombo_1_17, Tombo_1_16, HEAD
Branch point for: Tombo_1_17_1_branch
Changes since 1.3: +0 -1 lines
File MIME type: text/x-c++src
- remove dependencies to MemoNote
- add inf and bat files for PocketPC VGA

1 #include <windows.h>
2 #include <tchar.h>
3 #include <commctrl.h>
4
5 #include "Tombo.h"
6 #include "PasswordDialog.h"
7 #include "resource.h"
8 #include "UniConv.h"
9 #include "SipControl.h"
10 #include "Message.h"
11
12 #include "DialogTemplate.h"
13
14 //////////////////////////////////////////////////////////
15 // dtor
16 //////////////////////////////////////////////////////////
17
18 PasswordDialog::~PasswordDialog()
19 {
20 if (pPassword != NULL) {
21 char *p = pPassword;
22 // clear password area
23 while(*p) {
24 *p++ = '\0';
25 }
26 }
27 }
28
29 //////////////////////////////////////////////////////////
30 // Dlg proc
31 //////////////////////////////////////////////////////////
32
33 static BOOL APIENTRY DlgProc(HWND hDlg, UINT nMessage, WPARAM wParam, LPARAM lParam)
34 {
35 PasswordDialog *pDlg;
36 if (nMessage == WM_INITDIALOG) {
37 SetWindowLong(hDlg, DWL_USER, lParam);
38 pDlg = (PasswordDialog*)lParam;
39
40 pDlg->InitDialog(hDlg);
41 return TRUE;
42 }
43
44 pDlg = (PasswordDialog*)GetWindowLong(hDlg, DWL_USER);
45 if (pDlg == NULL) return FALSE;
46
47 switch (nMessage) {
48 case WM_COMMAND:
49 switch (wParam) {
50 case IDOK:
51 if (pDlg->OnOK(hDlg)) {
52 pDlg->ClearPassword(hDlg);
53 EndDialog(hDlg, IDOK);
54 }
55 break;
56 case IDCANCEL:
57 pDlg->ClearPassword(hDlg);
58 EndDialog(hDlg, IDCANCEL);
59 break;
60 }
61 return TRUE;
62 }
63 return FALSE;
64 }
65
66 //////////////////////////////////////////////////////////
67 // popup
68 //////////////////////////////////////////////////////////
69
70 DWORD PasswordDialog::Popup(HINSTANCE hInst, HWND hParent, BOOL b)
71 {
72 hInstance = hInst;
73 bVerify = b;
74
75 SipControl sc;
76 BOOL bSipStat, bResult;
77
78 bResult = sc.Init() && sc.GetSipStat(&bSipStat);
79 if (bResult) sc.SetSipStat(TRUE);
80
81 DWORD result;
82 result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_PASSWORD),
83 hParent, (DLGPROC)DlgProc, (LONG)this);
84
85 if (bResult) sc.SetSipStat(bSipStat);
86 return result;
87 }
88
89 //////////////////////////////////////////////////////////
90 // initialize
91 //////////////////////////////////////////////////////////
92
93 static DlgMsgRes aDlgMsg[] = {
94 { IDOK, MSG_ID_DLG_CMN_OK },
95 { IDCANCEL, MSG_ID_DLG_CMN_CANCEL },
96 };
97
98 void PasswordDialog::InitDialog(HWND hDlg)
99 {
100 OverrideDlgMsg(hDlg, MSG_ID_DLG_PASSWORD_TITLE, aDlgMsg, sizeof(aDlgMsg)/sizeof(DlgMsgRes));
101
102 ClearPassword(hDlg);
103 HWND hEdit2 = GetDlgItem(hDlg, IDC_PASS2);
104 EnableWindow(hEdit2, bVerify);
105 SendMessage(hEdit2, EM_SETREADONLY, (WPARAM)!bVerify, 0);
106 }
107
108 //////////////////////////////////////////////////////////
109 // Clear edit box
110 //////////////////////////////////////////////////////////
111
112 void PasswordDialog::ClearPassword(HWND hDlg)
113 {
114 HWND hEdit = GetDlgItem(hDlg, IDC_PASS);
115 HWND hEdit2 = GetDlgItem(hDlg, IDC_PASS2);
116 SetWindowText(hEdit, TEXT(""));
117 SetWindowText(hEdit2, TEXT(""));
118 }
119
120 //////////////////////////////////////////////////////////
121 // OK
122 //////////////////////////////////////////////////////////
123
124 static LPTSTR GetPass(HWND hEdit)
125 {
126 DWORD n = GetWindowTextLength(hEdit);
127 LPTSTR p = new TCHAR[n + 1];
128 if (p == NULL) {
129 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
130 return NULL;
131 }
132 GetWindowText(hEdit, p, n + 1);
133 p[n] = TEXT('\0');
134 return p;
135 }
136
137 BOOL PasswordDialog::OnOK(HWND hDlg)
138 {
139 HWND hEdit = GetDlgItem(hDlg, IDC_PASS);
140 HWND hEdit2 = GetDlgItem(hDlg, IDC_PASS2);
141 LPTSTR pPass1 = GetPass(hEdit);
142 if (!pPass1) return FALSE;
143 if (_tcslen(pPass1) == 0) {
144 WipeOutAndDelete(pPass1);
145 return FALSE;
146 }
147
148 LPTSTR pPass2;
149
150 if (bVerify) {
151 pPass2 = GetPass(hEdit2);
152 if (!pPass2) {
153 WipeOutAndDelete(pPass1);
154 return FALSE;
155 }
156 if (_tcscmp(pPass1, pPass2) != 0) {
157 TomboMessageBox(hDlg, MSG_PASS_NOT_MATCH, TEXT("Warning"), MB_ICONEXCLAMATION | MB_OK);
158 WipeOutAndDelete(pPass1);
159 WipeOutAndDelete(pPass2);
160 return FALSE;
161 }
162 WipeOutAndDelete(pPass2);
163 }
164 pPassword = ConvUnicode2SJIS(pPass1);
165
166 WipeOutAndDelete(pPass1);
167 return (pPassword != NULL);
168 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26