diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2020-08-05 18:50:16 +0200 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2020-08-06 00:36:44 +0200 |
commit | b0a6377878aad645adc0cf3a0d89188b1d0f1765 (patch) | |
tree | bb23c0c56125722f99e2a14fec020164ce8eeacf /src/Common | |
parent | 709964e156f52a28416f2c7350dacbbe665af9c9 (diff) | |
download | VeraCrypt-b0a6377878aad645adc0cf3a0d89188b1d0f1765.tar.gz VeraCrypt-b0a6377878aad645adc0cf3a0d89188b1d0f1765.zip |
Windows: Display a warning during system encryption wizard when typed password reaches maximum length and inform user that no more characters are allowed and that they are ignored.
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/Dlgcode.c | 78 |
1 files changed, 42 insertions, 36 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index 04f35044..42d93224 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -1219,6 +1219,44 @@ void EnableCloseButton (HWND hwndDlg) EnableMenuItem (GetSystemMenu (hwndDlg, FALSE), SC_CLOSE, MF_BYCOMMAND | MF_ENABLED); } +void HandlePasswordEditWmChar (HWND hwnd, WPARAM wParam) +{ + DWORD dwStartPos = 0, dwEndPos = 0; + short vk = VkKeyScanW ((WCHAR) wParam); + BYTE vkCode = LOBYTE (vk); + BYTE vkState = HIBYTE (vk); + bool ctrlPressed = (vkState & 2) && !(vkState & 4); + int dwMaxPassLen = (int) SendMessage (hwnd, EM_GETLIMITTEXT, 0, 0); + + // check if there is a selected text + SendMessage (hwnd, EM_GETSEL, (WPARAM) &dwStartPos, (LPARAM) &dwEndPos); + + if ((dwStartPos == dwEndPos) + && (vkCode != VK_DELETE) && (vkCode != VK_BACK) + && !ctrlPressed + && (GetWindowTextLength (hwnd) == dwMaxPassLen)) + { + EDITBALLOONTIP ebt; + DWORD dwTextSize = (DWORD) wcslen (GetString ("PASSWORD_MAXLENGTH_REACHED")) + 16; + WCHAR* szErrorText = (WCHAR*) malloc (dwTextSize * sizeof (WCHAR)); + + StringCchPrintf (szErrorText, dwTextSize, GetString ("PASSWORD_MAXLENGTH_REACHED"), dwMaxPassLen); + + ebt.cbStruct = sizeof( EDITBALLOONTIP ); + ebt.pszText = szErrorText; + ebt.pszTitle = lpszTitle; + ebt.ttiIcon = TTI_ERROR_LARGE; // tooltip warning icon + + SendMessage(hwnd, EM_SHOWBALLOONTIP, 0, (LPARAM)&ebt); + + MessageBeep (0xFFFFFFFF); + + free (szErrorText); + } + else + SendMessage(hwnd, EM_HIDEBALLOONTIP, 0, 0); +} + // Protects an input field from having its content updated by a Paste action (call ToBootPwdField() to use this). static LRESULT CALLBACK BootPwdFieldProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { @@ -1228,6 +1266,9 @@ static LRESULT CALLBACK BootPwdFieldProc (HWND hwnd, UINT message, WPARAM wParam { case WM_PASTE: return 1; + case WM_CHAR: + HandlePasswordEditWmChar (hwnd, wParam); + break; } return CallWindowProcW (wp, hwnd, message, wParam, lParam); @@ -1338,42 +1379,7 @@ static LRESULT CALLBACK NormalPwdFieldProc (HWND hwnd, UINT message, WPARAM wPar } break; case WM_CHAR: - { - DWORD dwStartPos = 0, dwEndPos = 0; - short vk = VkKeyScanW ((WCHAR) wParam); - BYTE vkCode = LOBYTE (vk); - BYTE vkState = HIBYTE (vk); - bool ctrlPressed = (vkState & 2) && !(vkState & 4); - int dwMaxPassLen = bUseLegacyMaxPasswordLength? MAX_LEGACY_PASSWORD : MAX_PASSWORD; - - // check if there is a selected text - SendMessage (hwnd, EM_GETSEL, (WPARAM) &dwStartPos, (LPARAM) &dwEndPos); - - if ((dwStartPos == dwEndPos) - && (vkCode != VK_DELETE) && (vkCode != VK_BACK) - && !ctrlPressed - && (GetWindowTextLength (hwnd) == dwMaxPassLen)) - { - EDITBALLOONTIP ebt; - DWORD dwTextSize = (DWORD) wcslen (GetString ("PASSWORD_MAXLENGTH_REACHED")) + 16; - WCHAR* szErrorText = (WCHAR*) malloc (dwTextSize * sizeof (WCHAR)); - - StringCchPrintf (szErrorText, dwTextSize, GetString ("PASSWORD_MAXLENGTH_REACHED"), dwMaxPassLen); - - ebt.cbStruct = sizeof( EDITBALLOONTIP ); - ebt.pszText = szErrorText; - ebt.pszTitle = lpszTitle; - ebt.ttiIcon = TTI_ERROR_LARGE; // tooltip warning icon - - SendMessage(hwnd, EM_SHOWBALLOONTIP, 0, (LPARAM)&ebt); - - MessageBeep (0xFFFFFFFF); - - free (szErrorText); - } - else - SendMessage(hwnd, EM_HIDEBALLOONTIP, 0, 0); - } + HandlePasswordEditWmChar (hwnd, wParam); break; } |