private void ShowPCAFormFromEntry(object sender, EventArgs e) { m_pcaForm = new PCADialog(); m_pweForm.UpdateEntryStrings(true, true, true); PCAInitData pcadata = new PCAInitData(m_pweForm.EntryRef); ExpiryControlGroup ecg = (ExpiryControlGroup)Tools.GetField("m_cgExpiry", m_pweForm); pcadata.Strings = m_pweForm.EntryStrings; if (ecg != null) { pcadata.Expires = ecg.Checked; pcadata.Expiry = ecg.Value; pcadata.SetExpiry = (pcadata.Expires != m_pweForm.EntryRef.Expires) || (pcadata.Expiry != m_pweForm.EntryRef.ExpiryTime); } pcadata.URL2 = pcadata.Strings.ReadSafe(Config.PCAURLField); DerefStrings(pcadata, m_pweForm.EntryRef); m_pcaForm.Init(pcadata, ProfilesOpening); if (m_pcaForm.ShowDialog(m_pweForm) == DialogResult.OK) { m_pweForm.EntryStrings.Set(PwDefs.PasswordField, m_pcaForm.NewPassword); if (ecg != null) { ecg.Checked = m_pcaForm.EntryExpiry.Checked; if (ecg.Checked) { ecg.Value = m_pcaForm.EntryExpiry.Value.ToUniversalTime(); } } if (string.IsNullOrEmpty(m_pcaForm.Sequence)) { m_pweForm.EntryStrings.Remove(Config.PCASequence); } else { m_pweForm.EntryStrings.Set(Config.PCASequence, new ProtectedString(false, m_pcaForm.Sequence)); } if (string.IsNullOrEmpty(m_pcaForm.URL2)) { m_pweForm.EntryStrings.Remove(Config.PCAURLField); } else { m_pweForm.EntryStrings.Set(Config.PCAURLField, new ProtectedString(false, m_pcaForm.URL2)); } m_pweForm.UpdateEntryStrings(false, true, true); } m_pcaForm.CleanupEx(); m_pcaForm = null; }
//Dereference placeholders in URL fields private void DerefStrings(PCAInitData pcadata, PwEntry pe) { if (m_miSprCompileFn == null) { return; } if (pcadata.URL.Contains("{")) { PwListItem pli = new PwListItem(pe); pcadata.URL = (string)m_miSprCompileFn.Invoke(null, new object[] { pcadata.URL, pli }); } if (pcadata.URL2.Contains("{")) { PwListItem pli = new PwListItem(pe); pcadata.URL2 = (string)m_miSprCompileFn.Invoke(null, new object[] { pcadata.URL2, pli }); } }
private void OnShowPCAForm(object sender, EventArgs e) { if (!SaveOldPassword()) { return; } m_pcaForm = new PCADialog(); PCAInitData pcadata = new PCAInitData(SelectedEntry); DerefStrings(pcadata, SelectedEntry); m_pcaForm.Init(pcadata, ProfilesOpening); if (m_pcaForm.ShowDialog(m_host.MainWindow) == DialogResult.OK) { SelectedEntry.CreateBackup(Program.MainForm.ActiveDatabase); SelectedEntry.Strings.Set(PwDefs.PasswordField, m_pcaForm.NewPassword); SelectedEntry.Expires = m_pcaForm.EntryExpiry.Checked; if (SelectedEntry.Expires) { SelectedEntry.ExpiryTime = m_pcaForm.EntryExpiry.Value.ToUniversalTime(); } if (string.IsNullOrEmpty(m_pcaForm.Sequence)) { SelectedEntry.Strings.Remove(Config.PCASequence); } else { SelectedEntry.Strings.Set(Config.PCASequence, new ProtectedString(false, m_pcaForm.Sequence)); } if (string.IsNullOrEmpty(m_pcaForm.URL2)) { SelectedEntry.Strings.Remove(Config.PCAURLField); } else { SelectedEntry.Strings.Set(Config.PCAURLField, new ProtectedString(false, m_pcaForm.URL2)); } SelectedEntry.Touch(true); Tools.RefreshEntriesList(true); } m_pcaForm.CleanupEx(); m_pcaForm = null; }
public void Init(PCAInitData pcadata, Action <object, CancelEventArgs> eProfilesOpening) { #region Translations Text = PluginTranslate.PluginName; tbURL2.PromptText = PluginTranslate.URL2Hint; gPasswords.Text = PluginTranslate.ChangePassword;; lOldPassword.Text = PluginTranslate.OldPW; lNewPassword.Text = PluginTranslate.NewPW; bCancel.Text = KPRes.Cancel; bChangePassword.Text = PluginTranslate.ButtonChangePW; bOldPasswordCopy.Text = bNewPasswordCopy.Text = KPRes.Copy; bSequence.Text = bOldPasswordType.Text = bNewPasswordType.Text = KPRes.AutoType; gSequence.Text = PluginTranslate.PCASequence; bSequenceEdit.Text = KPRes.EditCmd; bSequenceEdit.Width = bNewPasswordCopy.Width = bOldPasswordCopy.Width = Math.Max(bNewPasswordCopy.Width, bSequenceEdit.Width); bSequence.Left = bOldPasswordType.Left = bNewPasswordType.Left = bOldPasswordCopy.Left + bOldPasswordCopy.Width + 10; KeePassLib.Translation.KPFormCustomization kpfc = Program.Translation.Forms.Find(x => x.FullName == typeof(PwEntryForm).FullName); if (kpfc != null) { kpfc.ApplyTo(this); m_cbExpires.Text = StrUtil.RemoveAccelerator(m_cbExpires.Text); m_lblPasswordRepeat.Text = StrUtil.RemoveAccelerator(m_lblPasswordRepeat.Text); m_lblQuality.Text = StrUtil.RemoveAccelerator(m_lblQuality.Text); } if (!m_lblQuality.Text.EndsWith(":")) { m_lblQuality.Text += ":"; } #endregion m_OnProfilesOpening = eProfilesOpening; m_pcadata = pcadata; m_peCtxEntry = new PwEntry(true, true); m_peCtxEntry.Strings = m_pcadata.Strings; InitSequences(); rtbSequence.Text = m_pcadata.PCASequence; #region Handle SecureTextBoxEx SecureTextBoxEx.InitEx(ref tbPasswordOld); SecureTextBoxEx.InitEx(ref tbPasswordNew); SecureTextBoxEx.InitEx(ref tbPasswordNewRepeat); tbPasswordOld.TextEx = pcadata.OldPassword; tbPasswordOld.ReadOnly = true; ToolTip ttPwGen = new ToolTip(); #endregion SprEngine.FilterPlaceholderHints.Add(Config.PlaceholderOldPW); SprEngine.FilterPlaceholderHints.Add(Config.PlaceholderNewPW); #region password profile button - context menu, integration of PasswordProfileSync, ... ttPwGen.SetToolTip(GeneratePW, KPRes.GeneratePassword); GeneratePW.Image = UIUtil.CreateDropDownImage(Config.ScaleImage((Image)Program.Resources.GetObject("B16x16_Key_New"))); bChangePassword.Image = Config.ScaleImage(Resources.pca); //Password profile dropdown UpdateProfilesContextMenu(); #endregion Program.Translation.ApplyTo("KeePass.Forms.PwEntryForm.m_ctxDefaultTimes", m_ctxDefaultTimes.Items); bExpiry.Image = UIUtil.CreateDropDownImage(Config.ScaleImage((Image)Program.Resources.GetObject("B16x16_History"))); InitExpiryDate(); #region Show entry title - shortened if required string title = m_pcadata.Title; string user = m_pcadata.User; bool titleShortened = false, userShortened = false; while ((title.Length + user.Length) > 60) { if (title.Length > 30) { title = title.Substring(0, title.Length - 1); titleShortened = true; } else { user = user.Substring(0, user.Length - 1); userShortened = true; } } if (titleShortened) { title += "..."; } if (userShortened) { user += "..."; } if (string.IsNullOrEmpty(user)) { lEntry.Text = string.Format(PluginTranslate.EntryInfoNoUsername, KPRes.Entry, title); } else { lEntry.Text = string.Format(PluginTranslate.EntryInfo, KPRes.Entry, title, user); } #endregion Tools.GlobalWindowManager(this); }