Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        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;
        }