private void SelectCustomGenerator(string strUuid, string strCustomOptions) { int iSel = 0; try { if (string.IsNullOrEmpty(strUuid)) { return; } PwUuid uuid = new PwUuid(Convert.FromBase64String(strUuid)); CustomPwGenerator pwg = Program.PwGeneratorPool.Find(uuid); if (pwg == null) { return; } for (int i = 0; i < m_cmbCustomAlgo.Items.Count; ++i) { if ((m_cmbCustomAlgo.Items[i] as string) == pwg.Name) { iSel = i; if (strCustomOptions != null) { m_dictCustomOptions[pwg] = strCustomOptions; } break; } } } finally { m_cmbCustomAlgo.SelectedIndex = iSel; } }
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 SelectCustomGenerator(string strUuid, string strCustomOptions) { try { if (string.IsNullOrEmpty(strUuid)) { throw new ArgumentException(); } PwUuid uuid = new PwUuid(Convert.FromBase64String(strUuid)); CustomPwGenerator pwg = Program.PwGeneratorPool.Find(uuid); if (pwg == null) { throw new ArgumentException(); } bool bSet = false; for (int i = 0; i < m_cmbCustomAlgo.Items.Count; ++i) { if ((m_cmbCustomAlgo.Items[i] as string) == pwg.Name) { m_cmbCustomAlgo.SelectedIndex = i; if (strCustomOptions != null) { m_dictCustomOptions[pwg] = strCustomOptions; } bSet = true; break; } } if (!bSet) { throw new ArgumentException(); } } catch (Exception) { m_cmbCustomAlgo.SelectedIndex = 0; } }
private void OnBtnCustomOpt(object sender, EventArgs e) { CustomPwGenerator pwg = GetPwGenerator(); if (pwg == null) { Debug.Assert(false); return; } if (!pwg.SupportsOptions) { Debug.Assert(false); return; } string strCurOpt = string.Empty; if (m_dictCustomOptions.ContainsKey(pwg)) { strCurOpt = (m_dictCustomOptions[pwg] ?? string.Empty); } m_dictCustomOptions[pwg] = pwg.GetOptions(strCurOpt); }
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 PwProfile GetGenerationOptions() { PwProfile opt = new PwProfile(); opt.Name = m_cmbProfiles.Text; if (m_rbStandardCharSet.Checked) { opt.GeneratorType = PasswordGeneratorType.CharSet; } else if (m_rbPattern.Checked) { opt.GeneratorType = PasswordGeneratorType.Pattern; } else if (m_rbCustom.Checked) { opt.GeneratorType = PasswordGeneratorType.Custom; } opt.Length = (uint)m_numGenChars.Value; opt.CharSet = new PwCharSet(); if (m_cbUpperCase.Checked) { opt.CharSet.Add(PwCharSet.UpperCase); } if (m_cbLowerCase.Checked) { opt.CharSet.Add(PwCharSet.LowerCase); } if (m_cbDigits.Checked) { opt.CharSet.Add(PwCharSet.Digits); } if (m_cbSpecial.Checked) { opt.CharSet.Add(PwCharSet.SpecialChars); } if (m_cbHighAnsi.Checked) { opt.CharSet.Add(PwCharSet.HighAnsiChars); } if (m_cbMinus.Checked) { opt.CharSet.Add('-'); } if (m_cbUnderline.Checked) { opt.CharSet.Add('_'); } if (m_cbSpace.Checked) { opt.CharSet.Add(' '); } if (m_cbBrackets.Checked) { opt.CharSet.Add(PwCharSet.Brackets); } opt.CharSet.Add(m_tbCustomChars.Text); opt.Pattern = m_tbPattern.Text; opt.PatternPermutePassword = m_cbPatternPermute.Checked; opt.CollectUserEntropy = m_cbEntropy.Checked; opt.ExcludeLookAlike = m_cbExcludeLookAlike.Checked; opt.NoRepeatingCharacters = m_cbNoRepeat.Checked; opt.ExcludeCharacters = m_tbExcludeChars.Text; CustomPwGenerator pwg = GetPwGenerator(); opt.CustomAlgorithmUuid = ((pwg != null) ? Convert.ToBase64String( pwg.Uuid.UuidBytes) : string.Empty); if ((pwg != null) && m_dictCustomOptions.ContainsKey(pwg)) { opt.CustomAlgorithmOptions = (m_dictCustomOptions[pwg] ?? string.Empty); } else { opt.CustomAlgorithmOptions = string.Empty; } return(opt); }