private void OnClickKeyFileCreate(object sender, EventArgs e) { SaveFileDialogEx sfd = UIUtil.CreateSaveFileDialog(KPRes.KeyFileCreate, UrlUtil.StripExtension(UrlUtil.GetFileName(m_ioInfo.Path)) + "." + AppDefs.FileExtension.KeyFile, UIUtil.CreateFileTypeFilter("key", KPRes.KeyFiles, true), 1, "key", null); if (sfd.ShowDialog() == DialogResult.OK) { using (EntropyForm dlg = new EntropyForm()) { if (dlg.ShowDialog() == DialogResult.OK) { byte[] pbAdditionalEntropy = dlg.GeneratedEntropy; try { KcpKeyFile.Create(sfd.FileName, pbAdditionalEntropy); } catch (Exception exKC) { MessageService.ShowWarning(exKC); } } } EnableUserControls(); } }
private void PasswordGeneratorCommand(RowObject rowObject) { var passwordGenerator = new PwGeneratorForm(); PwProfile profile = null; if (!rowObject.Value.IsEmpty) { profile = KeePassLib.Cryptography.PasswordGenerator.PwProfile.DeriveFromPassword(rowObject.Value); } passwordGenerator.InitEx(profile, true, false); if (passwordGenerator.ShowDialog() == DialogResult.OK) { // Logic copied from PwEntryForm.OnPwGenOpen (PwEntryForm.cs) var entropy = EntropyForm.CollectEntropyIfEnabled(passwordGenerator.SelectedProfile); ProtectedString newPassword; PwGenerator.Generate(out newPassword, passwordGenerator.SelectedProfile, entropy, KeePass.Program.PwGeneratorPool); SetFieldValue(rowObject, newPassword); RefreshObject(rowObject); } UIUtil.DestroyForm(passwordGenerator); }
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 CreateNewPassword(PwProfile prof) { if (prof == null) { prof = PwProfile.DeriveFromPassword(m_pcadata.OldPassword); } if (prof.CollectUserEntropy && (m_pbEntropy == null)) { m_pbEntropy = EntropyForm.CollectEntropyIfEnabled(prof); } ProtectedString psNew; PwGenerator.Generate(out psNew, prof, m_pbEntropy, Program.PwGeneratorPool); m_icgNewPassword.SetPassword(psNew, true); }
private void OnPwGenOpen(object sender, EventArgs e) { PwGeneratorForm pgf = new PwGeneratorForm(); ProtectedString ps = current_password_field.TextEx; bool bAtLeastOneChar = (ps.Length > 0); PwProfile opt = PwProfile.DeriveFromPassword(ps); pgf.InitEx(bAtLeastOneChar ? opt : null, true, false); if (pgf.ShowDialog() == DialogResult.OK) { byte[] pbEntropy = EntropyForm.CollectEntropyIfEnabled(pgf.SelectedProfile); ProtectedString psNew; PwGenerator.Generate(out psNew, pgf.SelectedProfile, pbEntropy, Program.PwGeneratorPool); current_password_confirm_field.TextEx = current_password_field.TextEx = psNew; } }