Example #1
0
        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 ShowPCAButton DoShowPCAButton()
        {
            ShowPCAButton spb = ShowPCAButton.Error;

            if (m_pweForm == null)
            {
                return(spb);
            }

            PwEditMode   m  = PwEditMode.Invalid;
            PropertyInfo pi = typeof(PwEntryForm).GetProperty("EditModeEx");

            if (pi != null)
            {             //will work starting with KeePass 2.41, preferred way as it's a public attribute
                m = (PwEditMode)pi.GetValue(m_pweForm, null);
            }
            else
            {             // try reading private field
                m = (PwEditMode)Tools.GetField("m_pwEditMode", m_pweForm);
            }
            if (m == PwEditMode.Invalid)
            {
                return(spb);
            }
            spb = ShowPCAButton.NoShowOthers;
            if (m != PwEditMode.EditExistingEntry && m != PwEditMode.AddNewEntry)
            {
                return(spb);
            }

            spb = ShowPCAButton.NoShowMultiple;
            pi  = typeof(PwEntryForm).GetProperty("MultipleValuesEntryContext");
            object mvec = null;

            if (pi != null)
            {
                mvec = pi.GetValue(m_pweForm, null);
            }
            else
            {
                mvec = Tools.GetField("m_mvec", m_pweForm);
            }
            if (mvec != null)
            {
                return(spb);                          //NULL in case only one entry is edited/displayed
            }
            spb = m == PwEditMode.AddNewEntry ? ShowPCAButton.ShowAddSingle : ShowPCAButton.ShowEditSingle;

            return(spb);
        }
Example #3
0
        private PwEditMode EditMode()
        {
            PwEditMode m = PwEditMode.Invalid;

            if (m_pweForm == null)
            {
                return(m);
            }
            PropertyInfo pi = typeof(PwEntryForm).GetProperty("EditModeEx");

            if (pi != null)
            {             //will work starting with KeePass 2.41, preferred way as it's a public attribute
                m = (PwEditMode)pi.GetValue(m_pweForm, null);
            }
            else
            {             // try reading private field
                m = (PwEditMode)Tools.GetField("m_pwEditMode", m_pweForm);
            }
            return(m);
        }
Example #4
0
        public void InitEx(PwEntry pwEntry, PwEditMode pwMode, PwDatabase pwDatabase,
            ImageList ilIcons, bool bShowAdvancedByDefault, bool bSelectFullTitle)
        {
            Debug.Assert(pwEntry != null); if(pwEntry == null) throw new ArgumentNullException("pwEntry");
            Debug.Assert(pwMode != PwEditMode.Invalid); if(pwMode == PwEditMode.Invalid) throw new ArgumentException();
            Debug.Assert(ilIcons != null); if(ilIcons == null) throw new ArgumentNullException("ilIcons");

            m_pwEntry = pwEntry;
            m_pwEditMode = pwMode;
            m_pwDatabase = pwDatabase;
            m_ilIcons = ilIcons;
            m_bShowAdvancedByDefault = bShowAdvancedByDefault;
            m_bSelectFullTitle = bSelectFullTitle;

            m_vStrings = m_pwEntry.Strings.CloneDeep();
            m_vBinaries = m_pwEntry.Binaries.CloneDeep();
            m_atConfig = m_pwEntry.AutoType.CloneDeep();
            m_vHistory = m_pwEntry.History.CloneDeep();
        }
Example #5
0
        private void OnFormShown(object sender, EventArgs e)
        {
            PwEditMode   m         = PwEditMode.Invalid;
            PropertyInfo pEditMode = typeof(PwEntryForm).GetProperty("EditModeEx");

            if (pEditMode != null)             //will work starting with KeePass 2.41, preferred way as it's a public attribute
            {
                m = (PwEditMode)pEditMode.GetValue(m_pweForm, null);
            }
            else             // try reading private field
            {
                m = (PwEditMode)Tools.GetField("m_pwEditMode", m_pweForm);
            }
            PluginDebug.AddSuccess("Entryform shown, editmode: " + m.ToString(), 0);
            if ((m != PwEditMode.AddNewEntry) && (m != PwEditMode.EditExistingEntry))
            {
                return;
            }
            CustomContextMenuStripEx ctx = (CustomContextMenuStripEx)Tools.GetField("m_ctxDefaultTimes", m_pweForm);

            if (ctx != null)
            {
                ctx.Items.Add(new ToolStripSeparator());
                ToolStripMenuItem tsmiPED = CreatePEDMenu(false, true);
                ctx.Items.Add(tsmiPED);
                PluginDebug.AddSuccess("Found m_ctxDefaultTimes", 0);
            }
            else
            {
                PluginDebug.AddError("Could not find m_ctxDefaultTimes", 0);
            }

            PEDCalcValue   ped          = m_pweForm.EntryRef.GetPEDValue(true);
            CheckBox       cbExpires    = (CheckBox)Tools.GetControl("m_cbExpires", m_pweForm);
            DateTimePicker dtExpireDate = (DateTimePicker)Tools.GetControl("m_dtExpireDateTime", m_pweForm);
            DateTime       expiry       = ped.NewExpiryDateUtc.ToLocalTime();

            if (m == PwEditMode.EditExistingEntry)
            {
                cbExpires.CheckedChanged  += (o, e1) => CheckShowNewExpireDate();
                dtExpireDate.ValueChanged += (o, e1) => CheckShowNewExpireDate();
                SecureTextBoxEx password = (SecureTextBoxEx)Tools.GetControl("m_tbPassword", m_pweForm);
                password.TextChanged += (o, e1) => CheckShowNewExpireDate();
                Label lNewExpireDate = new Label();
                lNewExpireDate.Name = "PEDCalc_NewExpireDate";
                string sDate = string.Empty;
                m_iSelectedEntries = (int)m_host.MainWindow.GetSelectedEntriesCount();
                if ((Tools.KeePassVersion >= Configuration.KeePassMultipleEntries) && (m_iSelectedEntries > 1))
                {
                    PropertyInfo piMultiple = typeof(KeePass.Resources.KPRes).GetProperty("MultipleValues");
                    if (piMultiple != null)
                    {
                        sDate = piMultiple.GetValue(null, null) as string;
                    }
                    else
                    {
                        sDate = "?";
                    }
                }
                else if (dtExpireDate.Format == DateTimePickerFormat.Long)
                {
                    sDate = expiry.ToLongDateString();
                }
                else if (dtExpireDate.Format == DateTimePickerFormat.Short)
                {
                    sDate = expiry.ToShortDateString();
                }
                else if (dtExpireDate.Format == DateTimePickerFormat.Time)
                {
                    sDate = expiry.ToLongTimeString();
                }
                else
                {
                    sDate = expiry.ToString(dtExpireDate.CustomFormat);
                }
                lNewExpireDate.Text  = PluginTranslate.PluginName + ": " + sDate;
                lNewExpireDate.Left  = dtExpireDate.Left;
                lNewExpireDate.Top   = dtExpireDate.Top + dtExpireDate.Height + 2;
                lNewExpireDate.Width = dtExpireDate.Width;
                ToolTip tt = new ToolTip();
                tt.ToolTipTitle = PluginTranslate.PluginName;
                tt.ToolTipIcon  = ToolTipIcon.Info;
                tt.SetToolTip(lNewExpireDate, PluginTranslate.NewExpiryDateTooltip);
                dtExpireDate.Parent.Controls.Add(lNewExpireDate);
                int h = dtExpireDate.Parent.ClientSize.Height;
                if (h < lNewExpireDate.Top + lNewExpireDate.Height + 2)
                {
                    h = lNewExpireDate.Top + lNewExpireDate.Height + 2 - h;
                }
                else
                {
                    h = 0;
                }
                try
                {
                    dtExpireDate.Parent.Parent.Height += h;
                }
                catch { }
                CheckShowNewExpireDate();
            }

            if (m == PwEditMode.AddNewEntry)
            {
                if (ped.Off)
                {
                    return;
                }
                if ((cbExpires == null) || (dtExpireDate == null))
                {
                    Tools.ShowError(string.Format(PluginTranslate.ErrorInitExpiryDate, expiry.ToString()));
                    return;
                }
                m_pweForm.EntryRef.ExpiryTime = dtExpireDate.Value = expiry;
                m_pweForm.EntryRef.Expires    = cbExpires.Checked = true;
                PwEntry peInitialEntry = (PwEntry)Tools.GetField("m_pwInitialEntry", m_pweForm);
                if (peInitialEntry != null)
                {
                    peInitialEntry.Expires    = true;
                    peInitialEntry.ExpiryTime = expiry.ToUniversalTime();
                }
            }
        }
Example #6
0
        private void OnWindowAdded(object sender, GwmWindowEventArgs e)
        {
            if (!(e.Form is PwEntryForm))
            {
                return;
            }
            m_pweForm = (PwEntryForm)e.Form;
            PwEditMode m = EditMode();

            if (m == PwEditMode.Invalid)
            {
                return;
            }

            Control grpString = Tools.GetControl("m_grpstringFields", m_pweForm);
            Control lvStrings = Tools.GetControl("m_lvStrings", m_pweForm);

            cb_Remind      = new CheckBox();
            nup_RemindDays = new NumericUpDown();

            cb_Remind.Top                = 13;
            cb_Remind.Left               = 9;
            cb_Remind.Width              = 240;
            cb_Remind.Height             = 17;
            cb_Remind.Text               = Properties.strings.pcr_pwentry_cb_remind;
            cb_Remind.Name               = "pcr_cbRemind";
            cb_Remind.Enabled            = true;
            cb_Remind.CheckStateChanged += cbRemind_onCheckStateChanged;
            grpString.Parent.Controls.Add(cb_Remind);

            nup_RemindDays.Top     = 13;
            nup_RemindDays.Left    = cb_Remind.Right + 6;
            nup_RemindDays.Width   = 50;
            nup_RemindDays.Height  = 17;
            nup_RemindDays.Value   = 90;
            nup_RemindDays.Minimum = 1;
            nup_RemindDays.Maximum = Int32.MaxValue;
            nup_RemindDays.Enabled = false;
            nup_RemindDays.Name    = "pcr_nupRemindDays";
            grpString.Parent.Controls.Add(nup_RemindDays);

            grpString.Top    = grpString.Top + 30;
            grpString.Height = grpString.Height - 25;
            lvStrings.Height = lvStrings.Height - 25;

            if (m_pweForm.EntryStrings.Exists(_EntryStringKey))
            {
                cb_Remind.Checked    = true;
                nup_RemindDays.Value = Convert.ToInt32(m_pweForm.EntryStrings.Get(_EntryStringKey).ReadString());
            }

            if (m == PwEditMode.ViewReadOnlyEntry)
            {
                cb_Remind.Enabled      = false;
                nup_RemindDays.Enabled = false;
            }

            m_pweForm.EntrySaving += PwEntryForm_onEntrySaving;

            cb_Remind.BringToFront();
            nup_RemindDays.BringToFront();
        }