private void OnPwGenOpen(object sender, EventArgs e)
        {
            PwGeneratorForm pgf             = new PwGeneratorForm();
            ProtectedString ps              = new ProtectedString(true, current_password_field.ToUtf8());
            bool            bAtLeastOneChar = (ps.Length > 0);
            PwProfile       opt             = PwProfile.DeriveFromPassword(ps);

            pgf.InitEx(bAtLeastOneChar ? opt : null, true, false);
            if (pgf.ShowDialog() == DialogResult.OK)
            {
                byte[]          pbEntropy = EntropyForm.CollectEntropyIfEnabled(pgf.SelectedProfile);
                ProtectedString psNew;
                PwGenerator.Generate(out psNew, pgf.SelectedProfile, pbEntropy,
                                     Program.PwGeneratorPool);

                current_password_field.SetPassword(psNew.ReadUtf8());
                current_password_confirm_field.SetPassword(psNew.ReadUtf8());
            }
        }
Exemplo n.º 2
0
        private void keyPromtForm_onConfirmClick(object sender, EventArgs e)
        {
            if (!_keyPromtForm_usePw.Checked)
            {
                return;
            }

            // use the password from the input field as challange for the Yubikey
            string challenge = Encoding.UTF8.GetString(_keyPromtForm_secureEdit.ToUtf8());
            string response;

            if (yubiChallengeResponse(challenge, out response))
            {
                string password = deriveMasterPassword(challenge, response);
                _keyPromtForm_secureEdit.SetPassword(Encoding.UTF8.GetBytes(password));
            }
        }
Exemplo n.º 3
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            // Must work without a parent window
            Debug.Assert(this.StartPosition == FormStartPosition.CenterScreen);

            InitAdvancedTab();             // After translation, before resize

            GlobalWindowManager.AddWindow(this);

            string strTitle = (m_bSave ? KPRes.UrlSaveTitle : KPRes.UrlOpenTitle);
            string strDesc  = (m_bSave ? KPRes.UrlSaveDesc : KPRes.UrlOpenDesc);

            BannerFactory.CreateBannerEx(this, m_bannerImage,
                                         KeePass.Properties.Resources.B48x48_WWW, strTitle, strDesc);
            this.Icon = AppIcons.Default;
            this.Text = strTitle;

            FontUtil.AssignDefaultBold(m_lblUrl);
            FontUtil.AssignDefaultBold(m_lblUserName);
            FontUtil.AssignDefaultBold(m_lblPassword);
            FontUtil.AssignDefaultBold(m_lblRemember);

            m_secPassword.Attach(m_tbPassword, null, true);

            m_tbUrl.Text      = (m_ioc.IsLocalFile() ? string.Empty : m_ioc.Path);
            m_tbUserName.Text = m_ioc.UserName;
            m_secPassword.SetPassword(StrUtil.Utf8.GetBytes(m_ioc.Password));

            m_cmbCredSaveMode.Items.Add(KPRes.CredSaveNone);
            m_cmbCredSaveMode.Items.Add(KPRes.CredSaveUserOnly);
            m_cmbCredSaveMode.Items.Add(KPRes.CredSaveAll);

            if (m_ioc.CredSaveMode == IOCredSaveMode.UserNameOnly)
            {
                m_cmbCredSaveMode.SelectedIndex = 1;
            }
            else if (m_ioc.CredSaveMode == IOCredSaveMode.SaveCred)
            {
                m_cmbCredSaveMode.SelectedIndex = 2;
            }
            else
            {
                m_cmbCredSaveMode.SelectedIndex = 0;
            }

            if (!m_bCanRememberCred)
            {
                m_cmbCredSaveMode.SelectedIndex = 0;
                m_cmbCredSaveMode.Enabled       = false;
            }

            if ((m_tbUrl.TextLength > 0) && (m_tbUserName.TextLength > 0))
            {
                UIUtil.SetFocus(m_tbPassword, this);
            }
            else if (m_tbUrl.TextLength > 0)
            {
                UIUtil.SetFocus(m_tbUserName, this);
            }
            else
            {
                UIUtil.SetFocus(m_tbUrl, this);
            }
        }
 private void init_child_vals()
 {
     foreach (KeyValuePair <EntryTemplate, Control> pair in et_to_control)
     {
         if (pair.Value == null)
         {
             continue;
         }
         EntryTemplate t        = pair.Key;
         String        get_name = t.fieldName;
         if (t.fieldName == "@confirm")
         {
             get_name = PwDefs.PasswordField;
         }
         ProtectedString str = null;
         if (t.fieldName == "@override")
         {
             get_name = "";
             find_override_url_control(form);
             Debug.Assert(override_url_control != null || new_override_url_control != null);
             if (new_override_url_control != null)
             {
                 str = new ProtectedString(false, new_override_url_control.Text);
             }
             else
             {
                 str = new ProtectedString(false, override_url_control.Text);
             }
         }
         if (get_name != "")
         {
             str = form.EntryStrings.Get(get_name);
         }
         if (str == null)
         {
             str = new ProtectedString(t.type.StartsWith("Protected"), "");
         }
         if (t.type == "Inline" || t.type == "Inline URL")
         {
             TextBox box = (TextBox)pair.Value;
             String  val = str.ReadString();
             val      = val.Replace("\r", "");
             val      = val.Replace("\n", "\r\n");
             box.Text = val;
         }
         else if (t.type == "Protected Inline")
         {
             SecureEdit sedit = et_to_secure_edit[t];
             sedit.SetPassword(str.ReadUtf8());
         }
         else if (t.type == "Listbox")
         {
             ComboBox combobox = (ComboBox)pair.Value;
             combobox.SelectedItem = str.ReadString();
         }
         else if (t.type == "Checkbox")
         {
             bool     val;
             CheckBox box = (CheckBox)pair.Value;
             box.Checked = false;
             if (Boolean.TryParse(str.ReadString(), out val))
             {
                 box.Checked = val;
             }
         }
         else if (t.type == "Date" || t.type == "Time" || t.type == "Date Time")
         {
             DateTimePicker picker = (DateTimePicker)pair.Value;
             if (t.fieldName == "@exp_date")
             {
                 find_expires_control(form);
                 Debug.Assert(expires_control != null && expires_cbx_control != null);
                 picker.Value   = expires_control.Value;
                 picker.Checked = expires_cbx_control.Checked;
             }
             else
             {
                 DateTime val;
                 if (DateTime.TryParse(str.ReadString(), out val))
                 {
                     picker.Value = val;
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            GlobalWindowManager.AddWindow(this);

            this.Icon = AppIcons.Default;

            m_secPassword.Attach(m_tbPassword, null, true);

            ProxyServerType pst = Program.Config.Integration.ProxyType;

            if (pst == ProxyServerType.None)
            {
                m_rbNoProxy.Checked = true;
            }
            else if (pst == ProxyServerType.Manual)
            {
                m_rbManualProxy.Checked = true;
            }
            else
            {
                m_rbSystemProxy.Checked = true;
            }

            m_tbAddress.Text = Program.Config.Integration.ProxyAddress;
            m_tbPort.Text    = Program.Config.Integration.ProxyPort;

            string strUserName = Program.Config.Integration.ProxyUserName;
            string strPassword = Program.Config.Integration.ProxyPassword;

            ProxyAuthType pat = Program.Config.Integration.ProxyAuthType;

            if (pat == ProxyAuthType.Auto)
            {
                if ((strUserName.Length > 0) || (strPassword.Length > 0))
                {
                    pat = ProxyAuthType.Manual;
                }
                else
                {
                    pat = ProxyAuthType.Default;
                }
            }

            if (pat == ProxyAuthType.None)
            {
                m_rbAuthNone.Checked = true;
            }
            else if (pat == ProxyAuthType.Manual)
            {
                m_rbAuthManual.Checked = true;
            }
            else
            {
                m_rbAuthDefault.Checked = true;
            }

            m_tbUser.Text = strUserName;
            m_secPassword.SetPassword(StrUtil.Utf8.GetBytes(strPassword));

            EnableControlsEx();
        }