diff options
Diffstat (limited to 'src/Main/Forms/VolumePasswordPanel.cpp')
-rw-r--r-- | src/Main/Forms/VolumePasswordPanel.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/Main/Forms/VolumePasswordPanel.cpp b/src/Main/Forms/VolumePasswordPanel.cpp index 32b92edc..0555f339 100644 --- a/src/Main/Forms/VolumePasswordPanel.cpp +++ b/src/Main/Forms/VolumePasswordPanel.cpp @@ -145,105 +145,103 @@ namespace VeraCrypt }; if (enableKeyfiles) { SetDropTarget (new FileDropTarget (this)); foreach (wxWindow *c, GetChildren()) c->SetDropTarget (new FileDropTarget (this)); } Layout(); Fit(); } VolumePasswordPanel::~VolumePasswordPanel () { WipeTextCtrl (PasswordTextCtrl); WipeTextCtrl (ConfirmPasswordTextCtrl); } void VolumePasswordPanel::AddKeyfile (shared_ptr <Keyfile> keyfile) { if (!Keyfiles) Keyfiles.reset (new KeyfileList); Keyfiles->push_back (keyfile); UseKeyfilesCheckBox->SetValue (true); } void VolumePasswordPanel::SetPimValidator () { - wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST); // wxFILTER_NUMERIC does not exclude - . , etc. - const wxChar *valArr[] = { L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9" }; - validator.SetIncludes (wxArrayString (array_capacity (valArr), (const wxChar **) &valArr)); + wxTextValidator validator (wxFILTER_DIGITS); VolumePimTextCtrl->SetValidator (validator); } void VolumePasswordPanel::DisplayPassword (bool display, wxTextCtrl **textCtrl, int row) { FreezeScope freeze (this); bool isPim = (*textCtrl == VolumePimTextCtrl); int colspan = isPim? 1 : 2; size_t maxPasswordLength = CmdLine->ArgUseLegacyPassword? VolumePassword::MaxLegacySize : VolumePassword::MaxSize; wxTextCtrl *newTextCtrl = new wxTextCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, display ? 0 : wxTE_PASSWORD); newTextCtrl->SetMaxLength (isPim? MAX_PIM_DIGITS : maxPasswordLength); newTextCtrl->SetValue ((*textCtrl)->GetValue()); newTextCtrl->SetMinSize ((*textCtrl)->GetSize()); GridBagSizer->Detach ((*textCtrl)); GridBagSizer->Add (newTextCtrl, wxGBPosition (row, 1), wxGBSpan (1, colspan), wxEXPAND|wxBOTTOM, 5); (*textCtrl)->Show (false); WipeTextCtrl (*textCtrl); Fit(); Layout(); newTextCtrl->SetMinSize ((*textCtrl)->GetMinSize()); newTextCtrl->Connect (wxEVT_COMMAND_TEXT_UPDATED, isPim? wxCommandEventHandler (VolumePasswordPanel::OnPimChanged): wxCommandEventHandler (VolumePasswordPanel::OnTextChanged), nullptr, this); delete *textCtrl; *textCtrl = newTextCtrl; if (isPim) SetPimValidator (); } shared_ptr <VolumePassword> VolumePasswordPanel::GetPassword (bool bForceLegacyPassword) const { return GetPassword (PasswordTextCtrl, bForceLegacyPassword); } shared_ptr <VolumePassword> VolumePasswordPanel::GetPassword (wxTextCtrl *textCtrl, bool bLegacyPassword) const { shared_ptr <VolumePassword> password; wchar_t passwordBuf[VolumePassword::MaxSize + 1]; size_t maxPasswordLength = (bLegacyPassword || CmdLine->ArgUseLegacyPassword)? VolumePassword::MaxLegacySize: VolumePassword::MaxSize; - finally_do_arg (BufferPtr, BufferPtr (reinterpret_cast <byte *> (passwordBuf), sizeof (passwordBuf)), { finally_arg.Erase(); }); + finally_do_arg (BufferPtr, BufferPtr (reinterpret_cast <uint8 *> (passwordBuf), sizeof (passwordBuf)), { finally_arg.Erase(); }); #ifdef TC_WINDOWS int len = GetWindowText (static_cast <HWND> (textCtrl->GetHandle()), passwordBuf, VolumePassword::MaxSize + 1); password = ToUTF8Password (passwordBuf, len, maxPasswordLength); #else wxString passwordStr (textCtrl->GetValue()); // A copy of the password is created here by wxWidgets, which cannot be erased for (size_t i = 0; i < passwordStr.size() && i < maxPasswordLength; ++i) { passwordBuf[i] = (wchar_t) passwordStr[i]; passwordStr[i] = L'X'; } password = ToUTF8Password (passwordBuf, passwordStr.size() <= maxPasswordLength ? passwordStr.size() : maxPasswordLength, maxPasswordLength); #endif return password; } shared_ptr <Pkcs5Kdf> VolumePasswordPanel::GetPkcs5Kdf () const { try { int index = Pkcs5PrfChoice->GetSelection (); if ((wxNOT_FOUND == index) || (0 == index)) { // auto-detection return shared_ptr <Pkcs5Kdf> (); } else return Pkcs5Kdf::GetAlgorithm (wstring (Pkcs5PrfChoice->GetStringSelection())); } catch (ParameterIncorrect&) @@ -440,44 +438,45 @@ namespace VeraCrypt VolumePimHelpStaticText->SetForegroundColour(*wxRED); VolumePimHelpStaticText->SetLabel(LangString["PIM_CHANGE_WARNING"]); guiUpdated = true; } if (!pimChanged && VolumePimHelpStaticText->GetForegroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)) { VolumePimHelpStaticText->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); VolumePimHelpStaticText->SetLabel(LangString["IDC_PIM_HELP"]); guiUpdated = true; } if (guiUpdated) { Layout(); Fit(); GetParent()->Layout(); GetParent()->Fit(); } return guiUpdated; } void VolumePasswordPanel::OnUsePimCheckBoxClick( wxCommandEvent& event ) { if (EnablePimEntry) { wxWindow* layoutParent = TopOwnerParent? TopOwnerParent : GetParent(); PimCheckBox->Show (false); VolumePimStaticText->Show (true); VolumePimTextCtrl->Show (true); VolumePimHelpStaticText->Show (true); + VolumePimTextCtrl->SetFocus(); if (DisplayPasswordCheckBox->IsChecked ()) DisplayPassword (true, &VolumePimTextCtrl, 3); else { Layout(); Fit(); } layoutParent->Layout(); layoutParent->Fit(); } } } |