private void PCADialog_Shown(object sender, EventArgs e) { rtbSequence_TextChanged(null, null); PwProfile PPSProfile = null; string PPSProfileName = m_pcadata.Strings.ReadSafe(Config.ProfileLastUsedProfile); if (PPSProfileName == Config.ProfileAutoGenerated) { PPSProfile = Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile; } else { PPSProfile = PwGeneratorUtil.GetAllProfiles(false).Find(X => X.Name == PPSProfileName); } if (PPSProfile != null) { m_Profile = PPSProfile; CreateNewPassword(PPSProfile); } else { CreateNewPassword(PwProfile.DeriveFromPassword(m_pcadata.OldPassword)); } HandleURLFields(); }
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; } } }
private void OnProfilesSelectedIndexChanged(object sender, EventArgs e) { if (m_bBlockUIUpdate) { return; } string strProfile = m_cmbProfiles.Text; if (strProfile == CustomMeta) { } // Switch to custom -> nothing to do else if (strProfile == DeriveFromPrevious) { SetGenerationOptions(m_optInitial); } else if (strProfile == AutoGeneratedMeta) { SetGenerationOptions(Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile); } else { foreach (PwProfile pwgo in PwGeneratorUtil.GetAllProfiles(false)) { if (pwgo.Name == strProfile) { SetGenerationOptions(pwgo); break; } } } EnableControlsEx(false); }
private void ProfileClicked(object sender, ToolStripItemClickedEventArgs e) { if ((m_pweForm == null) || string.IsNullOrEmpty(e.ClickedItem.Text)) { return; } List <PwProfile> profiles = PwGeneratorUtil.GetAllProfiles(false); string prof = e.ClickedItem.Text.Replace("&", ""); m_pweForm.UpdateEntryStrings(true, true); PwProfile profile = profiles.Find(x => x.Name == prof); if (profile != null) { m_pweForm.EntryStrings.Set(Config.ProfileLastUsedProfile, new ProtectedString(false, prof)); } else if (prof == "(" + KPRes.AutoGeneratedPasswordSettings + ")") { m_pweForm.EntryStrings.Set(Config.ProfileLastUsedProfile, new ProtectedString(false, Config.ProfileAutoGenerated)); } else { m_pweForm.EntryStrings.Remove(Config.ProfileLastUsedProfile); } m_pweForm.UpdateEntryStrings(false, true); }
private static void GenPw(CommandLineArgs args) { List <PwProfile> l = PwGeneratorUtil.GetAllProfiles(false); PwProfile pp = null; string strProfile = args[ParamProfile]; if (!string.IsNullOrEmpty(strProfile)) { foreach (PwProfile ppEnum in l) { if (strProfile.Equals(ppEnum.Name, StrUtil.CaseIgnoreCmp)) { pp = ppEnum; break; } } } if (pp == null) { pp = new PwProfile(); } string strCount = args[ParamCount]; int iCount = 1; if (!string.IsNullOrEmpty(strCount)) { if (!int.TryParse(strCount, out iCount)) { iCount = 1; } } if (iCount < 0) { iCount = 1; } for (int i = 0; i < iCount; ++i) { try { ProtectedString ps; PwGenerator.Generate(out ps, pp, null, KeePass.Program.PwGeneratorPool); if (ps != null) { string str = ps.ReadString(); if (!string.IsNullOrEmpty(str)) { Console.WriteLine(str); } } } catch (Exception) { } } }
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; }
private void GenerateAndSetPassword(PwProfile prf) { if (prf == null) { Debug.Assert(false); return; } byte[] pbEntropy = EntropyForm.CollectEntropyIfEnabled(prf); PwEntry pe = ((m_fGetContextEntry != null) ? m_fGetContextEntry() : null); SetPassword(PwGeneratorUtil.GenerateAcceptable(prf, pbEntropy, pe, m_pdContext, true)); }
private void GeneratePreviewPasswords() { this.UseWaitCursor = true; m_pbPreview.Value = 0; m_tbPreview.Text = string.Empty; PwProfile pwOpt = GetGenerationOptions(); StringBuilder sbList = new StringBuilder(); uint n = MaxPreviewPasswords; if ((pwOpt.GeneratorType == PasswordGeneratorType.Custom) && string.IsNullOrEmpty(pwOpt.CustomAlgorithmUuid)) { n = 0; } PwEntry peContext = new PwEntry(true, true); MainForm mf = Program.MainForm; PwDatabase pdContext = ((mf != null) ? mf.ActiveDatabase : null); bool bAcceptAlways = false; for (uint i = 0; i < n; ++i) { Application.DoEvents(); string strError; ProtectedString psNew = PwGeneratorUtil.GenerateAcceptable( pwOpt, null, peContext, pdContext, false, ref bAcceptAlways, out strError); if (!string.IsNullOrEmpty(strError)) { sbList.Remove(0, sbList.Length); sbList.AppendLine(strError); break; } sbList.AppendLine(psNew.ReadString()); m_pbPreview.Value = (int)((100 * i) / MaxPreviewPasswords); } m_pbPreview.Value = 100; UIUtil.SetMultilineText(m_tbPreview, sbList.ToString()); this.UseWaitCursor = false; }
private void OnProfileClick(object sender, EventArgs e) { string prof = (sender as ToolStripMenuItem).Text; m_Profile = null; if (prof == "(" + KPRes.GenPwBasedOnPrevious + ")") { m_Profile = PwProfile.DeriveFromPassword(m_pcadata.OldPassword); } else if (prof == "(" + KPRes.AutoGeneratedPasswordSettings + ")") { m_Profile = Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile; } else { m_Profile = PwGeneratorUtil.GetAllProfiles(false).Find(x => x.Name == prof); } if (m_Profile != null) { CreateNewPassword(m_Profile); } }
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); } }
private void OnFormLoad(object sender, EventArgs e) { // Can be invoked by tray command; don't use CenterParent Debug.Assert(this.StartPosition == FormStartPosition.CenterScreen); GlobalWindowManager.AddWindow(this); m_strAdvControlText = m_tabAdvanced.Text; BannerFactory.CreateBannerEx(this, m_bannerImage, Properties.Resources.B48x48_KGPG_Gen, KPRes.PasswordOptions, KPRes.PasswordOptionsDesc); this.Icon = Properties.Resources.KeePass; UIUtil.SetButtonImage(m_btnProfileAdd, Properties.Resources.B16x16_FileSaveAs, false); UIUtil.SetButtonImage(m_btnProfileRemove, Properties.Resources.B16x16_EditDelete, true); FontUtil.AssignDefaultBold(m_rbStandardCharSet); FontUtil.AssignDefaultBold(m_rbPattern); FontUtil.AssignDefaultBold(m_rbCustom); FontUtil.AssignDefaultMono(m_tbPreview, true); m_ttMain.SetToolTip(m_btnProfileAdd, KPRes.GenProfileSaveDesc); m_ttMain.SetToolTip(m_btnProfileRemove, KPRes.GenProfileRemoveDesc); m_bBlockUIUpdate = true; m_cbUpperCase.Text += @" (A, B, C, ...)"; m_cbLowerCase.Text += @" (a, b, c, ...)"; m_cbDigits.Text += @" (0, 1, 2, ...)"; m_cbMinus.Text += @" (-)"; m_cbUnderline.Text += @" (_)"; m_cbSpace.Text += @" ( )"; m_cbSpecial.Text += @" (!, $, %, &&, ...)"; m_cbBrackets.Text += @" ([, ], {, }, (, ), <, >)"; m_cbNoRepeat.Text += @" *"; m_cbExcludeLookAlike.Text += @" (l|1I, O0) *"; m_lblExcludeChars.Text += @" *"; m_lblSecRedInfo.Text = @"* " + m_lblSecRedInfo.Text; m_cmbCustomAlgo.Items.Add(NoCustomAlgo); foreach (CustomPwGenerator pwg in Program.PwGeneratorPool) { m_cmbCustomAlgo.Items.Add(pwg.Name); } SelectCustomGenerator((m_optInitial != null) ? m_optInitial.CustomAlgorithmUuid : null, null); if (m_optInitial != null) { CustomPwGenerator pwg = GetPwGenerator(); if (pwg != null) { m_dictCustomOptions[pwg] = m_optInitial.CustomAlgorithmOptions; } } m_cmbProfiles.Items.Add(CustomMeta); if (m_optInitial != null) { m_cmbProfiles.Items.Add(DeriveFromPrevious); SetGenerationOptions(m_optInitial); } m_rbStandardCharSet.CheckedChanged += this.UpdateUIProc; m_rbPattern.CheckedChanged += this.UpdateUIProc; m_rbCustom.CheckedChanged += this.UpdateUIProc; m_numGenChars.ValueChanged += this.UpdateUIProc; m_cbUpperCase.CheckedChanged += this.UpdateUIProc; m_cbLowerCase.CheckedChanged += this.UpdateUIProc; m_cbDigits.CheckedChanged += this.UpdateUIProc; m_cbMinus.CheckedChanged += this.UpdateUIProc; m_cbUnderline.CheckedChanged += this.UpdateUIProc; m_cbSpace.CheckedChanged += this.UpdateUIProc; m_cbSpecial.CheckedChanged += this.UpdateUIProc; m_cbBrackets.CheckedChanged += this.UpdateUIProc; m_cbHighAnsi.CheckedChanged += this.UpdateUIProc; m_tbCustomChars.TextChanged += this.UpdateUIProc; m_tbPattern.TextChanged += this.UpdateUIProc; m_cbPatternPermute.CheckedChanged += this.UpdateUIProc; m_cbNoRepeat.CheckedChanged += this.UpdateUIProc; m_cbExcludeLookAlike.CheckedChanged += this.UpdateUIProc; m_tbExcludeChars.TextChanged += this.UpdateUIProc; m_cmbCustomAlgo.SelectedIndexChanged += this.UpdateUIProc; m_cmbProfiles.Items.Add(AutoGeneratedMeta); m_cmbProfiles.SelectedIndex = ((m_optInitial == null) ? 0 : 1); foreach (PwProfile ppw in PwGeneratorUtil.GetAllProfiles(true)) { m_cmbProfiles.Items.Add(ppw.Name); if (ppw.GeneratorType == PasswordGeneratorType.Custom) { CustomPwGenerator pwg = Program.PwGeneratorPool.Find(new PwUuid(Convert.FromBase64String(ppw.CustomAlgorithmUuid))); if (pwg != null) { m_dictCustomOptions[pwg] = ppw.CustomAlgorithmOptions; } } } if (m_optInitial == null) { // int nIndex = m_cmbProfiles.FindString(Program.Config.PasswordGenerator.LastUsedProfile.Name); // if(nIndex >= 0) m_cmbProfiles.SelectedIndex = nIndex; SetGenerationOptions(Program.Config.PasswordGenerator.LastUsedProfile); } if (m_bCanAccept == false) { m_btnOK.Visible = false; m_btnCancel.Text = KPRes.CloseButton; m_tabPreview.Text = KPRes.Generate; m_lblPreview.Visible = false; UIUtil.SetChecked(m_cbEntropy, false); m_cbEntropy.Enabled = false; } // Debug.Assert(this.ShowInTaskbar == false); // if(m_bForceInTaskbar) this.ShowInTaskbar = true; CustomizeForScreenReader(); m_bBlockUIUpdate = false; EnableControlsEx(false); }
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 void OnFormLoad(object sender, EventArgs e) { GlobalWindowManager.AddWindow(this); m_strAdvControlText = m_tabAdvanced.Text; m_bannerImage.Image = BannerFactory.CreateBanner(m_bannerImage.Width, m_bannerImage.Height, BannerStyle.Default, Properties.Resources.B48x48_KGPG_Gen, KPRes.PasswordOptions, KPRes.PasswordOptionsDesc); this.Icon = Properties.Resources.KeePass; m_ttMain.SetToolTip(m_btnProfileAdd, KPRes.GenProfileSaveDesc); m_ttMain.SetToolTip(m_btnProfileRemove, KPRes.GenProfileRemoveDesc); m_bBlockUIUpdate = true; m_cbUpperCase.Text += @" (A, B, C, ...)"; m_cbLowerCase.Text += @" (a, b, c, ...)"; m_cbDigits.Text += @" (0, 1, 2, ...)"; m_cbMinus.Text += @" (-)"; m_cbUnderline.Text += @" (_)"; m_cbSpace.Text += @" ( )"; m_cbSpecial.Text += @" (!, $, %, &&, ...)"; m_cbBrackets.Text += @" ([, ], {, }, (, ), <, >)"; m_cbNoRepeat.Text += @" *"; m_cbExcludeLookAlike.Text += @" (l|1I, O0) *"; m_lblExcludeChars.Text += @" *"; m_lblSecRedInfo.Text = @"* " + m_lblSecRedInfo.Text; m_cmbProfiles.Items.Add(CustomMeta); if (m_optInitial != null) { m_cmbProfiles.Items.Add(DeriveFromPrevious); SetGenerationOptions(m_optInitial); } m_rbStandardCharSet.CheckedChanged += this.UpdateUIProc; m_rbPattern.CheckedChanged += this.UpdateUIProc; m_numGenChars.ValueChanged += this.UpdateUIProc; m_cbUpperCase.CheckedChanged += this.UpdateUIProc; m_cbLowerCase.CheckedChanged += this.UpdateUIProc; m_cbDigits.CheckedChanged += this.UpdateUIProc; m_cbMinus.CheckedChanged += this.UpdateUIProc; m_cbUnderline.CheckedChanged += this.UpdateUIProc; m_cbSpace.CheckedChanged += this.UpdateUIProc; m_cbSpecial.CheckedChanged += this.UpdateUIProc; m_cbBrackets.CheckedChanged += this.UpdateUIProc; m_cbHighAnsi.CheckedChanged += this.UpdateUIProc; m_tbCustomChars.TextChanged += this.UpdateUIProc; m_tbPattern.TextChanged += this.UpdateUIProc; m_cbPatternPermute.CheckedChanged += this.UpdateUIProc; m_cbNoRepeat.CheckedChanged += this.UpdateUIProc; m_cbExcludeLookAlike.CheckedChanged += this.UpdateUIProc; m_tbExcludeChars.TextChanged += this.UpdateUIProc; m_cmbProfiles.Items.Add(AutoGeneratedMeta); m_cmbProfiles.SelectedIndex = (m_optInitial == null) ? 0 : 1; PwGeneratorUtil.AddStandardProfilesIfNoneAvailable(); foreach (PwProfile ppw in Program.Config.PasswordGenerator.UserProfiles) { m_cmbProfiles.Items.Add(ppw.Name); } if (m_optInitial == null) { // int nIndex = m_cmbProfiles.FindString(Program.Config.PasswordGenerator.LastUsedProfile.Name); // if(nIndex >= 0) m_cmbProfiles.SelectedIndex = nIndex; SetGenerationOptions(Program.Config.PasswordGenerator.LastUsedProfile); } if (m_bCanAccept == false) { m_btnOK.Visible = false; m_btnCancel.Text = KPRes.CloseButton; } Debug.Assert(this.ShowInTaskbar == false); if (m_bForceInTaskbar) { this.ShowInTaskbar = true; } CustomizeForScreenReader(); m_bBlockUIUpdate = false; 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); }