diff options
Diffstat (limited to 'plugins/NewStory/src/password.cpp')
-rw-r--r-- | plugins/NewStory/src/password.cpp | 180 |
1 files changed, 79 insertions, 101 deletions
diff --git a/plugins/NewStory/src/password.cpp b/plugins/NewStory/src/password.cpp index 88a8d55f36..b3184d18c0 100644 --- a/plugins/NewStory/src/password.cpp +++ b/plugins/NewStory/src/password.cpp @@ -31,7 +31,7 @@ bool CheckPassword(MCONTACT hContact, char *password) return false; } } - + db_free(&dbv); return true; } @@ -56,78 +56,66 @@ void SetPassword(MCONTACT hContact, char *password) INT_PTR CALLBACK PasswordDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { PasswordData *data = (PasswordData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - switch (msg) - { - case WM_INITDIALOG: - { - data = new PasswordData; - data->attempt = 0; - data->hContact = (MCONTACT)lParam; - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)data); - - RECT rc, rcMe; - SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); - GetWindowRect(hwnd, &rcMe); - SetWindowPos(hwnd, hwnd, - rc.left+((rc.right-rc.left) - (rcMe.right-rcMe.left))/2, - rc.top+((rc.bottom-rc.top) - (rcMe.bottom-rcMe.top))/2, - 0, 0, SWP_NOSIZE|SWP_NOZORDER); - - SetFocus(GetDlgItem(hwnd, IDC_PASSWORD)); - return TRUE; - } - - case WM_COMMAND: + switch (msg) { + case WM_INITDIALOG: + data = new PasswordData; + data->attempt = 0; + data->hContact = (MCONTACT)lParam; + SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)data); + + RECT rc, rcMe; + SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); + GetWindowRect(hwnd, &rcMe); + SetWindowPos(hwnd, hwnd, + rc.left + ((rc.right - rc.left) - (rcMe.right - rcMe.left)) / 2, + rc.top + ((rc.bottom - rc.top) - (rcMe.bottom - rcMe.top)) / 2, + 0, 0, SWP_NOSIZE | SWP_NOZORDER); + + SetFocus(GetDlgItem(hwnd, IDC_PASSWORD)); + return TRUE; + + case WM_COMMAND: { - switch(LOWORD(wParam)) - { - case IDOK: + switch (LOWORD(wParam)) { + case IDOK: + data->attempt++; { - data->attempt++; int length = GetWindowTextLengthA(GetDlgItem(hwnd, IDC_PASSWORD)); - char *input = new char[length+1]; - GetWindowTextA(GetDlgItem(hwnd, IDC_PASSWORD), input, length+1); - if (CheckPassword(data->hContact, input)) - { + char *input = new char[length + 1]; + GetWindowTextA(GetDlgItem(hwnd, IDC_PASSWORD), input, length + 1); + if (CheckPassword(data->hContact, input)) { MessageBeep(MB_OK); EndDialog(hwnd, 1); - } else - { - if (data->attempt >= 3) - { - MessageBoxA(hwnd, "Sorry, but you've not managed to type\r\nthe correct password in 3 attempts.", "Newstory", MB_ICONHAND|MB_OK); + } + else { + if (data->attempt >= 3) { + MessageBoxA(hwnd, "Sorry, but you've not managed to type\r\nthe correct password in 3 attempts.", "Newstory", MB_ICONHAND | MB_OK); EndDialog(hwnd, 0); - } else - { + } + else { MessageBeep(MB_ICONHAND); SetWindowTextA(GetDlgItem(hwnd, IDC_PASSWORD), ""); } } - delete [] input; - return TRUE; + delete[] input; } + return TRUE; - case IDCANCEL: - { - EndDialog(hwnd, 0); - return TRUE; - } + case IDCANCEL: + EndDialog(hwnd, 0); + return TRUE; } break; } - case WM_CLOSE: - { - DestroyWindow(hwnd); - return TRUE; - } + case WM_CLOSE: + DestroyWindow(hwnd); + return TRUE; - case WM_DESTROY: - { - delete data; - data = 0; - SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); - } + case WM_DESTROY: + delete data; + data = 0; + SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); } return FALSE; } @@ -141,7 +129,7 @@ bool AskPassword(MCONTACT hContact) return true; } db_free(&dbv); - + if (DialogBoxParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_PASSWORD), 0, PasswordDlgProc, (LPARAM)hContact)) return true; return false; @@ -151,82 +139,72 @@ bool AskPassword(MCONTACT hContact) INT_PTR CALLBACK ChangePasswordDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwnd, GWLP_USERDATA); - switch (msg) - { - case WM_INITDIALOG: + switch (msg) { + case WM_INITDIALOG: { hContact = (MCONTACT)lParam; SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)hContact); -// RECT rc, rcMe; -// SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); -// GetWindowRect(hwnd, &rcMe); -// SetWindowPos(hwnd, hwnd, -// rc.left+((rc.right-rc.left) - (rcMe.right-rcMe.left))/2, -// rc.top+((rc.bottom-rc.top) - (rcMe.bottom-rcMe.top))/2, -// 0, 0, SWP_NOSIZE|SWP_NOZORDER); + // RECT rc, rcMe; + // SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); + // GetWindowRect(hwnd, &rcMe); + // SetWindowPos(hwnd, hwnd, + // rc.left+((rc.right-rc.left) - (rcMe.right-rcMe.left))/2, + // rc.top+((rc.bottom-rc.top) - (rcMe.bottom-rcMe.top))/2, + // 0, 0, SWP_NOSIZE|SWP_NOZORDER); SetFocus(GetDlgItem(hwnd, IDC_PASSWORD)); return TRUE; } - case WM_COMMAND: + case WM_COMMAND: { - switch(LOWORD(wParam)) - { - case IDOK: + switch (LOWORD(wParam)) { + case IDOK: { int length = GetWindowTextLengthA(GetDlgItem(hwnd, IDC_PASSWORD)); - char *input = new char[length+1]; - GetWindowTextA(GetDlgItem(hwnd, IDC_PASSWORD), input, length+1); + char *input = new char[length + 1]; + GetWindowTextA(GetDlgItem(hwnd, IDC_PASSWORD), input, length + 1); length = GetWindowTextLengthA(GetDlgItem(hwnd, IDC_PASSWORD2)); - char *input2 = new char[length+1]; - GetWindowTextA(GetDlgItem(hwnd, IDC_PASSWORD2), input2, length+1); + char *input2 = new char[length + 1]; + GetWindowTextA(GetDlgItem(hwnd, IDC_PASSWORD2), input2, length + 1); length = GetWindowTextLengthA(GetDlgItem(hwnd, IDC_PASSWORD3)); - char *input3 = new char[length+1]; - GetWindowTextA(GetDlgItem(hwnd, IDC_PASSWORD3), input3, length+1); + char *input3 = new char[length + 1]; + GetWindowTextA(GetDlgItem(hwnd, IDC_PASSWORD3), input3, length + 1); - if (lstrcmpA(input2, input3) || !CheckPassword(hContact, input)) - { + if (lstrcmpA(input2, input3) || !CheckPassword(hContact, input)) { MessageBeep(MB_ICONHAND); SetWindowTextA(GetDlgItem(hwnd, IDC_PASSWORD), ""); SetWindowTextA(GetDlgItem(hwnd, IDC_PASSWORD2), ""); SetWindowTextA(GetDlgItem(hwnd, IDC_PASSWORD3), ""); - } else - { + } + else { SetPassword(hContact, input2); EndDialog(hwnd, 0); } - delete [] input; - delete [] input2; - delete [] input3; - - return TRUE; + delete[] input; + delete[] input2; + delete[] input3; } + return TRUE; - case IDCANCEL: - { - EndDialog(hwnd, 0); - return TRUE; - } + case IDCANCEL: + EndDialog(hwnd, 0); + return TRUE; } break; } - case WM_CLOSE: - { - EndDialog(hwnd, 0); - DestroyWindow(hwnd); - return TRUE; - } + case WM_CLOSE: + EndDialog(hwnd, 0); + DestroyWindow(hwnd); + return TRUE; - case WM_DESTROY: - { - SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); - } + case WM_DESTROY: + SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); } return FALSE; } |