"Fossies" - the Fresh Open Source Software Archive

Member "filezilla-3.48.1/src/interface/asksavepassworddialog.cpp" (6 May 2020, 2955 Bytes) of package /linux/misc/FileZilla_3.48.1_src.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "asksavepassworddialog.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.48.0_vs_3.48.1.

    1 #include "filezilla.h"
    2 #include "asksavepassworddialog.h"
    3 #include "Options.h"
    4 #include "filezillaapp.h"
    5 #include "xrc_helper.h"
    6 #include "sitemanager.h"
    7 #include <libfilezilla/util.hpp>
    8 
    9 bool CAskSavePasswordDialog::Create(wxWindow*)
   10 {
   11     if (!Load(nullptr, _T("ID_ASK_SAVE_PASSWORD"))) {
   12         return false;
   13     }
   14 
   15     wxGetApp().GetWrapEngine()->WrapRecursive(this, 2, "");
   16 
   17     auto onChange = [this](wxEvent const&) {
   18         bool checked = xrc_call(*this, "ID_PASSWORDS_USEMASTERPASSWORD", &wxRadioButton::GetValue);
   19         xrc_call(*this, "ID_MASTERPASSWORD", &wxControl::Enable, checked);
   20         xrc_call(*this, "ID_MASTERPASSWORD_REPEAT", &wxControl::Enable, checked);
   21 
   22     };
   23     onChange(wxCommandEvent());
   24 
   25     XRCCTRL(*this, "ID_PASSWORDS_SAVE", wxEvtHandler)->Bind(wxEVT_RADIOBUTTON, onChange);
   26     XRCCTRL(*this, "ID_PASSWORDS_NOSAVE", wxEvtHandler)->Bind(wxEVT_RADIOBUTTON, onChange);
   27     XRCCTRL(*this, "ID_PASSWORDS_USEMASTERPASSWORD", wxEvtHandler)->Bind(wxEVT_RADIOBUTTON, onChange);
   28 
   29     XRCCTRL(*this, "wxID_OK", wxButton)->Bind(wxEVT_BUTTON, &CAskSavePasswordDialog::OnOk, this);
   30 
   31     return true;
   32 }
   33 
   34 void CAskSavePasswordDialog::OnOk(wxCommandEvent& event)
   35 {
   36     bool useMaster = xrc_call(*this, "ID_PASSWORDS_USEMASTERPASSWORD", &wxRadioButton::GetValue);
   37     if (useMaster) {
   38         std::wstring pw = xrc_call(*this, "ID_MASTERPASSWORD", &wxTextCtrl::GetValue).ToStdWstring();
   39         std::wstring repeat = xrc_call(*this, "ID_MASTERPASSWORD_REPEAT", &wxTextCtrl::GetValue).ToStdWstring();
   40         if (pw != repeat) {
   41             wxMessageBoxEx(_("The entered passwords are not the same."), _("Invalid input"));
   42             return;
   43         }
   44 
   45         if (pw.size() < 8) {
   46             wxMessageBoxEx(_("The master password needs to be at least 8 characters long."), _("Invalid input"));
   47             return;
   48         }
   49 
   50         auto priv = fz::private_key::from_password(fz::to_utf8(pw), fz::random_bytes(fz::private_key::salt_size));
   51         auto pub = priv.pubkey();
   52         if (!pub) {
   53             wxMessageBoxEx(_("Could not generate key"), _("Error"));
   54             return;
   55         }
   56         else {
   57             COptions::Get()->SetOption(OPTION_DEFAULT_KIOSKMODE, 0);
   58             COptions::Get()->SetOption(OPTION_MASTERPASSWORDENCRYPTOR, fz::to_wstring_from_utf8(pub.to_base64()));
   59         }
   60     }
   61     else {
   62         bool save = xrc_call(*this, "ID_PASSWORDS_SAVE", &wxRadioButton::GetValue);
   63         COptions::Get()->SetOption(OPTION_DEFAULT_KIOSKMODE, save ? 0 : 1);
   64         COptions::Get()->SetOption(OPTION_MASTERPASSWORDENCRYPTOR, std::wstring());
   65     }
   66     event.Skip();
   67 }
   68 
   69 bool CAskSavePasswordDialog::Run(wxWindow* parent)
   70 {
   71     bool ret = true;
   72 
   73     if (COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE) == 0 && COptions::Get()->GetOptionVal(OPTION_PROMPTPASSWORDSAVE) != 0 &&
   74         !CSiteManager::HasSites() && COptions::Get()->GetOption(OPTION_MASTERPASSWORDENCRYPTOR).empty())
   75     {
   76         CAskSavePasswordDialog dlg;
   77         if (dlg.Create(parent)) {
   78             ret = dlg.ShowModal() == wxID_OK;
   79             if (ret) {
   80                 COptions::Get()->SetOption(OPTION_PROMPTPASSWORDSAVE, 0);
   81             }
   82         }
   83     }
   84     else {
   85         COptions::Get()->SetOption(OPTION_PROMPTPASSWORDSAVE, 0);
   86     }
   87 
   88     return ret;
   89 }