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);
        }
Пример #2
0
        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));
        }
Пример #3
0
        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);
        }
Пример #4
0
        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;
            }
        }