| 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 |
} |