VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2020-08-05 16:50:16 (GMT)
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2020-08-05 22:36:44 (GMT)
commitb0a6377878aad645adc0cf3a0d89188b1d0f1765 (patch)
treebb23c0c56125722f99e2a14fec020164ce8eeacf
parent709964e156f52a28416f2c7350dacbbe665af9c9 (diff)
downloadVeraCrypt-b0a6377878aad645adc0cf3a0d89188b1d0f1765.zip
VeraCrypt-b0a6377878aad645adc0cf3a0d89188b1d0f1765.tar.gz
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.
-rw-r--r--src/Common/Dlgcode.c78
1 files changed, 42 insertions, 36 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 04f3504..42d9322 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;
}