From 709964e156f52a28416f2c7350dacbbe665af9c9 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Wed, 5 Aug 2020 18:18:31 +0200 Subject: Windows: Display warning message with correct maximum length value when password is truncated --- src/Common/Dlgcode.c | 44 +++++++++++++++++++++++++++++++++++++++----- src/Common/Language.xml | 6 +++--- 2 files changed, 42 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index 6fcd16c3..04f35044 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -1288,9 +1288,13 @@ static LRESULT CALLBACK NormalPwdFieldProc (HWND hwnd, UINT message, WPARAM wPar if (curLen == 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 = GetString ("PASSWORD_MAXLENGTH_REACHED"); + ebt.pszText = szErrorText; ebt.pszTitle = lpszTitle; ebt.ttiIcon = TTI_ERROR_LARGE; // tooltip warning icon @@ -1298,20 +1302,28 @@ static LRESULT CALLBACK NormalPwdFieldProc (HWND hwnd, UINT message, WPARAM wPar MessageBeep (0xFFFFFFFF); + free (szErrorText); + bBlock = true; } else if ((txtlen + curLen) > dwMaxPassLen) { EDITBALLOONTIP ebt; + DWORD dwTextSize = (DWORD) wcslen (GetString ("PASSWORD_PASTED_TRUNCATED")) + 16; + WCHAR* szErrorText = (WCHAR*) malloc (dwTextSize * sizeof (WCHAR)); + + StringCchPrintf (szErrorText, dwTextSize, GetString ("PASSWORD_PASTED_TRUNCATED"), dwMaxPassLen); ebt.cbStruct = sizeof( EDITBALLOONTIP ); - ebt.pszText = GetString ("PASSWORD_PASTED_TRUNCATED"); + ebt.pszText = szErrorText; ebt.pszTitle = lpszTitle; ebt.ttiIcon = TTI_WARNING_LARGE; // tooltip warning icon SendMessage(hwnd, EM_SHOWBALLOONTIP, 0, (LPARAM)&ebt); MessageBeep (0xFFFFFFFF); + + free (szErrorText); } else SendMessage(hwnd, EM_HIDEBALLOONTIP, 0, 0); @@ -1343,15 +1355,21 @@ static LRESULT CALLBACK NormalPwdFieldProc (HWND hwnd, UINT message, WPARAM wPar && (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 = GetString ("PASSWORD_MAXLENGTH_REACHED"); + 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); @@ -13229,7 +13247,17 @@ BOOL GetPassword (HWND hwndDlg, UINT ctrlID, char* passValue, int bufSize, BOOL { SetFocus (GetDlgItem(hwndDlg, ctrlID)); if (GetLastError () == ERROR_INSUFFICIENT_BUFFER) - Error ((bufSize == (MAX_LEGACY_PASSWORD + 1))? "LEGACY_PASSWORD_UTF8_TOO_LONG": "PASSWORD_UTF8_TOO_LONG", hwndDlg); + { + DWORD dwTextSize = (DWORD) wcslen (GetString ("PASSWORD_UTF8_TOO_LONG")) + 16; + WCHAR* szErrorText = (WCHAR*) malloc (dwTextSize * sizeof (WCHAR)); + + // bufSize is equal to maximum password length plus one + StringCchPrintf (szErrorText, dwTextSize, GetString ("PASSWORD_UTF8_TOO_LONG"), (bufSize - 1)); + + ErrorDirect (szErrorText, hwndDlg); + + free (szErrorText); + } else Error ("PASSWORD_UTF8_INVALID", hwndDlg); } @@ -14899,15 +14927,21 @@ void PasswordEditDropTarget::GotDrop(CLIPFORMAT format) if (bTruncated) { EDITBALLOONTIP ebt; + DWORD dwTextSize = (DWORD) wcslen (GetString ("PASSWORD_PASTED_TRUNCATED")) + 16; + WCHAR* szErrorText = (WCHAR*) malloc (dwTextSize * sizeof (WCHAR)); + + StringCchPrintf (szErrorText, dwTextSize, GetString ("PASSWORD_PASTED_TRUNCATED"), maxLen); ebt.cbStruct = sizeof( EDITBALLOONTIP ); - ebt.pszText = GetString ("PASSWORD_PASTED_TRUNCATED"); + ebt.pszText = szErrorText; ebt.pszTitle = lpszTitle; ebt.ttiIcon = TTI_WARNING_LARGE; // tooltip warning icon SendMessage(hChild, EM_SHOWBALLOONTIP, 0, (LPARAM)&ebt); MessageBeep (0xFFFFFFFF); + + free (szErrorText); } } diff --git a/src/Common/Language.xml b/src/Common/Language.xml index e0e657c9..3144c3a6 100644 --- a/src/Common/Language.xml +++ b/src/Common/Language.xml @@ -1378,7 +1378,7 @@ Include &PIM when caching pre-boot authentication password Include PIM when caching a password Make disconnected network drives available for mounting - The entered password is too long: its UTF-8 representation exceeds 128 bytes. + The entered password is too long: its UTF-8 representation exceeds %d bytes. The entered password contains Unicode characters that couldn't be converted to UTF-8 representation. Error: Failed to load a system library. The volume file size specified in the command line is incompatible with selected exFAT filesystem. @@ -1421,8 +1421,8 @@ Block TRIM command on system partition/drive ERROR: Windows EFI system loader could not be located on the disk. Operation will be aborted. It is currently not possible to encrypt a system if SecureBoot is enabled and if VeraCrypt custom keys are not loaded into the machine firmware. SecureBoot needs to be disabled in the BIOS configuration in order to allow system encryption to proceed. - Pasted text truncated because the password maximum length is 128 characters - Password already reached its maximum length of 128 characters.\nNo additional character is allowed. + Pasted text truncated because the password maximum length is %d characters + Password already reached its maximum length of %d characters.\nNo additional character is allowed. Select the language to use during the installation: ERROR: The size of the file container is larger than the available free space on disk. Allow Windows Disk Defragmenter to defragment non-system partition/drive -- cgit v1.2.3