Beispiel #1
0
        private void OnBtnProfileRemove(object sender, EventArgs e)
        {
            string strProfile = m_cmbProfiles.Text;

            if ((strProfile == CustomMeta) || (strProfile == DeriveFromPrevious) ||
                (strProfile == AutoGeneratedMeta) || PwGeneratorUtil.IsBuiltInProfile(strProfile))
            {
                return;
            }

            m_cmbProfiles.SelectedIndex = 0;
            for (int i = 0; i < m_cmbProfiles.Items.Count; ++i)
            {
                if (strProfile == m_cmbProfiles.Items[i].ToString())
                {
                    m_cmbProfiles.Items.RemoveAt(i);

                    List <PwProfile> lUser = Program.Config.PasswordGenerator.UserProfiles;
                    for (int j = 0; j < lUser.Count; ++j)
                    {
                        if (lUser[j].Name == strProfile)
                        {
                            lUser.RemoveAt(j);
                            break;
                        }
                    }

                    break;
                }
            }
        }
Beispiel #2
0
        private void EnableControlsEx(bool bSwitchToCustomProfile)
        {
            if (m_bBlockUIUpdate)
            {
                return;
            }

            m_bBlockUIUpdate = true;

            if (bSwitchToCustomProfile)
            {
                m_cmbProfiles.SelectedIndex = 0;
            }

            m_lblNumGenChars.Enabled                = m_numGenChars.Enabled = m_cbUpperCase.Enabled =
                m_cbLowerCase.Enabled               = m_cbDigits.Enabled = m_cbMinus.Enabled =
                    m_cbUnderline.Enabled           = m_cbSpace.Enabled = m_cbSpecial.Enabled =
                        m_cbBrackets.Enabled        = m_cbHighAnsi.Enabled = m_lblCustomChars.Enabled =
                            m_tbCustomChars.Enabled = m_rbStandardCharSet.Checked;
            m_tbPattern.Enabled = m_cbPatternPermute.Enabled =
                m_rbPattern.Checked;

            string strProfile = m_cmbProfiles.Text;

            m_btnProfileRemove.Enabled = ((strProfile != CustomMeta) &&
                                          (strProfile != DeriveFromPrevious) && (strProfile != AutoGeneratedMeta) &&
                                          !PwGeneratorUtil.IsBuiltInProfile(strProfile));

            m_tabAdvanced.Text = ((m_cbExcludeLookAlike.Checked ||
                                   m_cbNoRepeat.Checked || (m_tbExcludeChars.Text.Length > 0)) ?
                                  (m_strAdvControlText + " (!)") : m_strAdvControlText);

            m_cmbCustomAlgo.Enabled = m_rbCustom.Checked;
            if (m_rbCustom.Checked == false)
            {
                m_btnCustomOpt.Enabled = false;
            }
            else
            {
                CustomPwGenerator pwg = GetPwGenerator();
                if (pwg != null)
                {
                    m_btnCustomOpt.Enabled = pwg.SupportsOptions;
                }
                else
                {
                    m_btnCustomOpt.Enabled = false;
                }
            }

            m_bBlockUIUpdate = false;
        }
Beispiel #3
0
        public void UpdateProfilesContextMenu()
        {
            Image ImgProfPrevious = Config.ScaleImage((Image)Program.Resources.GetObject("B16x16_CompFile"));
            Image ImgProfAuto     = Config.ScaleImage((Image)Program.Resources.GetObject("B16x16_FileNew"));
            Image ImgProfStandard = Config.ScaleImage((Image)Program.Resources.GetObject("B16x16_KOrganizer"));

            ctxPWGen.Items.Clear();
            ctxPWGen.ImageScalingSize = new Size(DpiUtil.ScaleIntX(16), DpiUtil.ScaleIntY(16));

            ToolStripMenuItem           miProfile   = new ToolStripMenuItem("Password Generator", Config.ScaleImage((Image)Program.Resources.GetObject("B16x16_Key_New"), 16, 16), OnPWGenOpen);
            Dictionary <string, string> translation = Program.Translation.SafeGetStringTableDictionary("KeePass.Forms.PwEntryForm.m_ctxPwGen");
            string translated = string.Empty;

            if (translation.TryGetValue("m_ctxPwGenOpen", out translated))
            {
                miProfile.Text = translated;
            }
            ctxPWGen.Items.Add(miProfile);
            ctxPWGen.Items.Add(new ToolStripSeparator());
            miProfile     = new ToolStripMenuItem("(" + KPRes.GenPwBasedOnPrevious + ")", ImgProfPrevious, OnProfileClick);
            miProfile.Tag = "(" + KPRes.GenPwBasedOnPrevious + ")";
            ctxPWGen.Items.Add(miProfile);
            miProfile     = new ToolStripMenuItem("(" + KPRes.AutoGeneratedPasswordSettings + ")", ImgProfAuto, OnProfileClick);
            miProfile.Tag = "(" + KPRes.AutoGeneratedPasswordSettings + ")";
            ctxPWGen.Items.Add(miProfile);
            bool bHideBuiltIn = ((Program.Config.UI.UIFlags & (ulong)AceUIFlags.HideBuiltInPwGenPrfInEntryDlg) != 0);

            foreach (PwProfile pw in PwGeneratorUtil.GetAllProfiles(true))
            {
                if (bHideBuiltIn && PwGeneratorUtil.IsBuiltInProfile(pw.Name))
                {
                    continue;
                }
                miProfile     = new ToolStripMenuItem(pw.Name, ImgProfStandard, OnProfileClick);
                miProfile.Tag = pw.Name;
                ctxPWGen.Items.Add(miProfile);
            }
        }
Beispiel #4
0
        private void OnBtnProfileSave(object sender, EventArgs e)
        {
            List <string> lNames = new List <string>();

            lNames.Add(AutoGeneratedMeta);
            foreach (PwProfile pwExisting in Program.Config.PasswordGenerator.UserProfiles)
            {
                lNames.Add(pwExisting.Name);
            }

            SingleLineEditForm slef = new SingleLineEditForm();

            slef.InitEx(KPRes.GenProfileSave, KPRes.GenProfileSaveDesc,
                        KPRes.GenProfileSaveDescLong, Properties.Resources.B48x48_KGPG_Gen,
                        string.Empty, lNames.ToArray());

            if (slef.ShowDialog() == DialogResult.OK)
            {
                string strProfile = slef.ResultString;

                PwProfile pwCurrent = GetGenerationOptions();
                pwCurrent.Name = strProfile;

                if (strProfile.Equals(CustomMeta) || strProfile.Equals(DeriveFromPrevious) ||
                    (strProfile.Length == 0) || PwGeneratorUtil.IsBuiltInProfile(strProfile))
                {
                    MessageService.ShowWarning(KPRes.FieldNameInvalid);
                }
                else if (strProfile == AutoGeneratedMeta)
                {
                    pwCurrent.Name = string.Empty;
                    Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile = pwCurrent;
                    m_cmbProfiles.SelectedIndex = m_cmbProfiles.FindString(AutoGeneratedMeta);
                }
                else
                {
                    List <PwProfile> lUser = Program.Config.PasswordGenerator.UserProfiles;

                    bool bExists = false;
                    for (int i = 0; i < lUser.Count; ++i)
                    {
                        if (lUser[i].Name.Equals(strProfile, StrUtil.CaseIgnoreCmp))
                        {
                            lUser[i] = pwCurrent;

                            for (int j = 0; j < m_cmbProfiles.Items.Count; ++j)
                            {
                                if (m_cmbProfiles.Items[j].ToString().Equals(strProfile,
                                                                             StrUtil.CaseIgnoreCmp))
                                {
                                    m_bBlockUIUpdate            = true;
                                    m_cmbProfiles.Items[j]      = strProfile;                                // Fix case
                                    m_bBlockUIUpdate            = false;
                                    m_cmbProfiles.SelectedIndex = j;
                                    bExists = true;
                                    break;
                                }
                            }

                            break;
                        }
                    }

                    if (!bExists)
                    {
                        m_bBlockUIUpdate = true;

                        List <PwProfile> lAll = PwGeneratorUtil.GetAllProfiles(false);
                        for (int c = 0; c < lAll.Count; ++c)
                        {
                            m_cmbProfiles.Items.RemoveAt(m_cmbProfiles.Items.Count - 1);
                        }

                        lUser.Add(pwCurrent);

                        int iNewSel = 0;
                        foreach (PwProfile pwAdd in PwGeneratorUtil.GetAllProfiles(true))
                        {
                            m_cmbProfiles.Items.Add(pwAdd.Name);
                            if (pwAdd.Name == strProfile)
                            {
                                iNewSel = m_cmbProfiles.Items.Count - 1;
                            }
                        }

                        m_bBlockUIUpdate            = false;
                        m_cmbProfiles.SelectedIndex = iNewSel;
                    }
                }
            }
            UIUtil.DestroyForm(slef);

            EnableControlsEx(false);
        }
        private List <ToolStripItem> ConstructMenuItems()
        {
            List <ToolStripItem> l          = new List <ToolStripItem>();
            List <char>          lAvailKeys = new List <char>(PwCharSet.MenuAccels);
            ProtectedString      ps         = GetPassword();

            GFunc <string, Image, EventHandler, object, ToolStripMenuItem> fAdd =
                delegate(string strText, Image img, EventHandler ehClick,
                         object oTag)
            {
                string str = StrUtil.EncodeMenuText(strText ?? string.Empty);
                str = StrUtil.AddAccelerator(str, lAvailKeys);

                ToolStripMenuItem tsmi = new ToolStripMenuItem(str);
                if (img != null)
                {
                    tsmi.Image = img;
                }
                if (ehClick != null)
                {
                    tsmi.Click += ehClick;
                }
                if (oTag != null)
                {
                    tsmi.Tag = oTag;
                }

                l.Add(tsmi);
                return(tsmi);
            };

            fAdd(KPRes.PwGenOpen, Properties.Resources.B16x16_Key_New,
                 this.OnGenOpen, null);

            l.Add(new ToolStripSeparator());

            ToolStripMenuItem tsmiDerive = fAdd(GenDeriveFromPrevious,
                                                Properties.Resources.B16x16_CompFile, this.OnGenDeriveFromPrevious, null);

            if (IsMultipleValues(ps))
            {
                tsmiDerive.Enabled = false;
            }

            fAdd(GenAuto, Properties.Resources.B16x16_FileNew, this.OnGenAuto, null);

            bool bHideBuiltIn = ((Program.Config.UI.UIFlags &
                                  (ulong)AceUIFlags.HideBuiltInPwGenPrfInEntryDlg) != 0);
            bool bFirst = true;

            foreach (PwProfile prf in PwGeneratorUtil.GetAllProfiles(true))
            {
                if (prf == null)
                {
                    Debug.Assert(false); continue;
                }

                if (bHideBuiltIn && PwGeneratorUtil.IsBuiltInProfile(prf.Name))
                {
                    continue;
                }

                if (bFirst)
                {
                    l.Add(new ToolStripSeparator());
                    bFirst = false;
                }

                fAdd(prf.Name, Properties.Resources.B16x16_KOrganizer,
                     this.OnGenProfile, prf);
            }

            return(l);
        }