private void PasswordGeneratorCommand(RowObject rowObject) { var passwordGenerator = new PwGeneratorForm(); PwProfile profile = null; if (!rowObject.Value.IsEmpty) { profile = KeePassLib.Cryptography.PasswordGenerator.PwProfile.DeriveFromPassword(rowObject.Value); } passwordGenerator.InitEx(profile, true, false); if (passwordGenerator.ShowDialog() == DialogResult.OK) { // Logic copied from PwEntryForm.OnPwGenOpen (PwEntryForm.cs) var entropy = EntropyForm.CollectEntropyIfEnabled(passwordGenerator.SelectedProfile); ProtectedString newPassword; PwGenerator.Generate(out newPassword, passwordGenerator.SelectedProfile, entropy, KeePass.Program.PwGeneratorPool); SetFieldValue(rowObject, newPassword); RefreshObject(rowObject); } UIUtil.DestroyForm(passwordGenerator); }
private void PrepareEntryForm() { m_pweForm.PasswordGeneratorContextMenu.Opening += ProfilesOpening; m_pweForm.PasswordGeneratorContextMenu.ItemClicked += ProfileClicked; m_pweForm.FormClosed += OnFormClosed; m_pwgForm = null; LoadDBProfiles(); //try to get the edit mode var spb = DoShowPCAButton(); if (spb == ShowPCAButton.Error) { m_pweForm.Shown += OnEntryFormShown; //Reading the edit mode failed, try this as fallback } else if (spb == ShowPCAButton.NoShowMultiple) { PluginDebug.AddInfo("Multiple entries selected - No PCA button added", 0); return; } else if (spb == ShowPCAButton.NoShowOthers) { PluginDebug.AddInfo("Neither CREATE nor EDIT mode - No PCA button added", 0); return; } SaveOldPassword(); m_pweForm.Resize += OnEntryFormResize; //create plugin button right below the button for generating a new password CreatePCAButton(); #region add context menu to plugin button ContextMenuStrip cmsPCA = new ContextMenuStrip(); ToolStripMenuItem menuitem = new ToolStripMenuItem(PluginTranslate.OldPWCopy, m_btnPCA.Image, PasswordCopyClick); menuitem.Name = PluginTranslate.PluginName + "OldCopy"; cmsPCA.Items.Add(menuitem); menuitem = new ToolStripMenuItem(PluginTranslate.OldPWType, m_btnPCA.Image, PasswordTypeClick); menuitem.Name = PluginTranslate.PluginName + "OldType"; cmsPCA.Items.Add(menuitem); menuitem = new ToolStripMenuItem(PluginTranslate.NewPWCopy, m_btnPCA.Image, PasswordCopyClick); menuitem.Name = PluginTranslate.PluginName + "NewCopy"; cmsPCA.Items.Add(menuitem); menuitem = new ToolStripMenuItem(PluginTranslate.NewPWType, m_btnPCA.Image, PasswordTypeClick); menuitem.Name = PluginTranslate.PluginName + "NewType"; cmsPCA.Items.Add(menuitem); cmsPCA.Items.Add(new ToolStripSeparator()); menuitem = new ToolStripMenuItem(PluginTranslate.PluginName + "...", m_btnPCA.Image, ShowPCAFormFromEntry); menuitem.Name = PluginTranslate.PluginName + "ShowPCAFormFromEntry"; cmsPCA.Items.Add(menuitem); m_btnPCA.ContextMenuStrip = cmsPCA; cmsPCA.Opening += cmsPCAOpening; m_btnPCA.Click += (o, x) => m_btnPCA.ContextMenuStrip.Show(m_btnPCA, 0, m_btnPCA.Height); #endregion //finally add the button to the form m_btnPCA.BringToFront(); }
private void PrepareEntryForm() { m_pweForm.PasswordGeneratorContextMenu.Opening += ProfilesOpening; m_pweForm.PasswordGeneratorContextMenu.ItemClicked += ProfileClicked; m_pweForm.FormClosed += OnFormClosed; m_pwgForm = null; LoadDBProfiles(); if (m_host.MainWindow.GetSelectedEntriesCount() != 1) { PluginDebug.AddInfo("Multiple entries selected - No PCA button added", 0); return; } SaveOldPassword(); //try to get the edit mode PwEditMode m = EditMode(); if (m == PwEditMode.Invalid) { m_pweForm.Shown += OnEntryFormShown; //Reading the edit mode failed, try this as fallback } else if (m != PwEditMode.EditExistingEntry) { return; // we're not in edit mode } m_pweForm.Resize += OnEntryFormResize; //create plugin button right below the button for generating a new password CreatePCAButton(); #region add context menu to plugin button ContextMenuStrip cmsPCA = new ContextMenuStrip(); ToolStripMenuItem menuitem = new ToolStripMenuItem(PluginTranslate.OldPWCopy, m_btnPCA.Image, PasswordCopyClick); menuitem.Name = PluginTranslate.PluginName + "OldCopy"; cmsPCA.Items.Add(menuitem); menuitem = new ToolStripMenuItem(PluginTranslate.OldPWType, m_btnPCA.Image, PasswordTypeClick); menuitem.Name = PluginTranslate.PluginName + "OldType"; cmsPCA.Items.Add(menuitem); menuitem = new ToolStripMenuItem(PluginTranslate.NewPWCopy, m_btnPCA.Image, PasswordCopyClick); menuitem.Name = PluginTranslate.PluginName + "NewCopy"; cmsPCA.Items.Add(menuitem); menuitem = new ToolStripMenuItem(PluginTranslate.NewPWType, m_btnPCA.Image, PasswordTypeClick); menuitem.Name = PluginTranslate.PluginName + "NewType"; cmsPCA.Items.Add(menuitem); cmsPCA.Items.Add(new ToolStripSeparator()); menuitem = new ToolStripMenuItem(PluginTranslate.PluginName + "...", m_btnPCA.Image, ShowPCAFormFromEntry); menuitem.Name = PluginTranslate.PluginName + "ShowPCAFormFromEntry"; cmsPCA.Items.Add(menuitem); m_btnPCA.ContextMenuStrip = cmsPCA; m_btnPCA.Click += (o, x) => m_btnPCA.ContextMenuStrip.Show(m_btnPCA, 0, m_btnPCA.Height); #endregion //finally add the button to the form m_btnPCA.BringToFront(); }
private void OnPWGenOpen(object sender, EventArgs e) { ProtectedString ps = m_icgNewPassword.GetPasswordEx(); PwProfile opt = PwProfile.DeriveFromPassword(ps); PwGeneratorForm pgf = new PwGeneratorForm(); pgf.InitEx((!ps.IsEmpty ? opt : null), true, false); if (pgf.ShowDialog() == DialogResult.OK) { CreateNewPassword(pgf.SelectedProfile); m_Profile = pgf.SelectedProfile; } UpdateProfilesContextMenu(); UIUtil.DestroyForm(pgf); }
private void OnPwGenOpen(object sender, EventArgs e) { PwGeneratorForm pgf = new PwGeneratorForm(); ProtectedString ps = current_password_field.TextEx; 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_confirm_field.TextEx = current_password_field.TextEx = psNew; } }
private void OnFormClosed(object sender, FormClosedEventArgs e) { if (sender is PwGeneratorForm) { ProfileClicked(sender, new ToolStripItemClickedEventArgs(new ToolStripMenuItem(m_pwgForm.SelectedProfile.Name))); List <PwProfile> dbProfiles = Program.Config.PasswordGenerator.UserProfiles.GetDBProfiles(); bool changed = false; UpdateDBProfiles(m_profiles, dbProfiles, out changed); if (changed) { m_host.MainWindow.UpdateUI(false, null, false, null, false, null, true); } } else if (sender is PwEntryForm) { m_pweForm = null; } m_pwgForm = null; }
private void OnGenOpen(object sender, EventArgs e) { PwProfile prf = null; ProtectedString ps = (GetPassword() ?? ProtectedString.Empty); if (!ps.IsEmpty && !IsMultipleValues(ps)) { prf = PwProfile.DeriveFromPassword(ps); } PwGeneratorForm pgf = new PwGeneratorForm(); pgf.InitEx(prf, true, false); if (pgf.ShowDialog() == DialogResult.OK) { GenerateAndSetPassword(pgf.SelectedProfile); } UIUtil.DestroyForm(pgf); }
private void OnWindowAdded(object sender, GwmWindowEventArgs e) { if (e.Form is PwGeneratorForm) { m_pwgForm = (PwGeneratorForm)e.Form; m_pwgForm.Shown += OnPwGeneratorFormShown; m_pwgForm.FormClosed += OnFormClosed; LoadDBProfiles(); return; } if (e.Form is SingleLineEditForm) { HandleProfileSaveForm(e.Form as SingleLineEditForm); return; } if (!(e.Form is PwEntryForm)) { return; //Not the entry form => exit } m_pweForm = (PwEntryForm)e.Form; PrepareEntryForm(); }