Exemplo n.º 1
0
        // -------------------------------------------------------------------------------------------------------------------------------------------

        #region GeneratePasswords

        private void pbGenerate_Click(object sender, EventArgs e)
        {
            PasswordGeneratorOptions options = PasswordGeneratorOptions.None;

            if (rbCapitalsFirst.Checked)
            {
                options |= PasswordGeneratorOptions.Capitals | PasswordGeneratorOptions.CapitalsFirstInChunks;
            }
            else if (rbCapitalsLast.Checked)
            {
                options |= PasswordGeneratorOptions.Capitals | PasswordGeneratorOptions.CapitalsLastInChunks;
            }
            else if (rbCapitalsRandom.Checked)
            {
                options |= PasswordGeneratorOptions.Capitals;
            }

            // if (cbCapitals.Checked)
            //    options |= PasswordGeneratorOptions.Capitals;
            if (cbSpecials.Checked)
            {
                options |= PasswordGeneratorOptions.Specials;
                if (!cbBlanks.Checked)
                {
                    options |= PasswordGeneratorOptions.SpecialsNotBlank;
                }
            }

            if (string.IsNullOrEmpty(tbFixedSeparator.Text))
            {
                tbFixedSeparator.Text = PasswordGenerator.SeparatorsDefault.Substring(0, 1);
            }

            char fixedSeparator = tbFixedSeparator.Text[0];

            if (cbSeparators.Checked)
            {
                options |= PasswordGeneratorOptions.Separators;
                if (cbRotSeparators.Checked)
                {
                    options |= PasswordGeneratorOptions.SeparatorRotation;
                }
            }

            PasswordGeneratorOptionsEx optionsEx = new PasswordGeneratorOptionsEx()
            {
                Options             = options,
                CapitalsMinimum     = 1,
                CapitalsMaximum     = (int)nudCapitalsMax.Value,
                SpecialGroupSymbols = tbSpecials.Text,
                SpecialGroupsMin    = 1,
                SpecialGroupsMax    = (int)nudSpecialsMax.Value,
                FixedSeparatorChar  = fixedSeparator,
                RotatingSeparators  = tbSeparators.Text
            };


            PasswordCollection passwords = new PasswordCollection();

            for (int count = 0; count < nudPassToGen.Value; ++count)
            {
                string password = _passwordGenerator.Generate((int)nudPassLen.Value, optionsEx);
                passwords.Append(_passwordGenerator.LastPassword);
            }

            dgvPasswords.AutoGenerateColumns = false;

            var           bindingList = new SortableBindingList <PasswordCollectionItem>(passwords.Passwords);
            BindingSource source      = new BindingSource(bindingList, null);

            dgvPasswords.DataSource = source;
        }
Exemplo n.º 2
0
        private void pbSave_Click(object sender, EventArgs e)
        {
            Dictionary <PasswordChunkType, int> weights = AdjustWeights();

            if (weights == null)
            {
                return;
            }

            ApplicationConfiguration configuration = new ApplicationConfiguration();

            configuration.PasswordLength = (int)nudPassLen.Value;
            configuration.PasswordCount  = (int)nudPassToGen.Value;

            PasswordGeneratorOptions options = PasswordGeneratorOptions.None;

            if (rbCapitalsFirst.Checked)
            {
                options |= PasswordGeneratorOptions.Capitals | PasswordGeneratorOptions.CapitalsFirstInChunks;
            }
            else if (rbCapitalsLast.Checked)
            {
                options |= PasswordGeneratorOptions.Capitals | PasswordGeneratorOptions.CapitalsLastInChunks;
            }
            else if (rbCapitalsRandom.Checked)
            {
                options |= PasswordGeneratorOptions.Capitals;
            }


            if (cbSpecials.Checked)
            {
                options |= PasswordGeneratorOptions.Specials;
                if (!cbBlanks.Checked)
                {
                    options |= PasswordGeneratorOptions.SpecialsNotBlank;
                }
            }

            if (string.IsNullOrEmpty(tbFixedSeparator.Text))
            {
                tbFixedSeparator.Text = PasswordGenerator.SeparatorsDefault.Substring(0, 1);
            }

            char fixedSeparator = tbFixedSeparator.Text[0];

            if (cbSeparators.Checked)
            {
                options |= PasswordGeneratorOptions.Separators;
                if (cbRotSeparators.Checked)
                {
                    options |= PasswordGeneratorOptions.SeparatorRotation;
                }
            }

            PasswordGeneratorOptionsEx optionsEx = new PasswordGeneratorOptionsEx()
            {
                Options             = options,
                CapitalsMinimum     = 1,
                CapitalsMaximum     = (int)nudCapitalsMax.Value,
                SpecialGroupSymbols = tbSpecials.Text,
                SpecialGroupsMin    = 1,
                SpecialGroupsMax    = (int)nudSpecialsMax.Value,
                FixedSeparatorChar  = fixedSeparator,
                RotatingSeparators  = tbSeparators.Text
            };

            configuration.Options = optionsEx;

            configuration.ChunkTypeWeights = PasswordChunkTypeWeight.GetChunkTypeWeights(weights);

            string errorText;

            configuration.Save(ApplicationConfiguration.ConfigurationFilePath, out errorText);

            NewConfiguration = configuration;

            DialogResult = DialogResult.OK;
        }