예제 #1
0
 private void addItemToListBox(PasswordParameters passwordObject)
 {
     List<PasswordParameters> passwords = new List<PasswordParameters>();
     for (int i = 0; i < GeneratedPasswordsListBox.Items.Count; i++) {
         passwords.Add((PasswordParameters)GeneratedPasswordsListBox.Items[i]);
     }
     GeneratedPasswordsListBox.Items.Clear();
     GeneratedPasswordsListBox.Items.Add(passwordObject);
     for (int i = 0; i < passwords.Count; i++) {
         GeneratedPasswordsListBox.Items.Add(passwords[i]);
     }
 }
예제 #2
0
        //This function will store all the information about a currentpasswords parameters in a structure to be recalled when the user clicks on a password generated
        private PasswordParameters createPasswordObject(PasswordParameters passwordObject, string password)
        {
            passwordObject.checkBoxes = storeSymbolsChecked();

            passwordObject.passwordSymbolDropdown = PasswordSymbolDropdown.SelectedIndex;
            passwordObject.passwordLength = (int)PasswordLengthUpDown.Value;

            passwordObject.capitalSymbolDropdown = CapitalLetterSymbolDropdown.SelectedIndex;
            passwordObject.capitalLength = (int)CapitalLetterRequiredUpDown.Value;

            passwordObject.lowerSymbolDropdown = LowercaseLetterSymbolDropdown.SelectedIndex;
            passwordObject.lowerLength = (int)LowercaseLetterRequiredUpDown.Value;

            passwordObject.symbolSymbolDropdown = SymbolsRequiredSymbolDropdown.SelectedIndex;
            passwordObject.symbolLength = (int)SymbolsRequiredUpDown.Value;

            passwordObject.numberSymbolDropdown = NumbersRequiredSymbolDropdown.SelectedIndex;
            passwordObject.numberLength = (int)NumbersRequiredUpDown.Value;

            passwordObject.password = password;

            return passwordObject;
        }
예제 #3
0
        private void GeneratePasswordButton_Click(object sender, EventArgs e)
        {
            PasswordLengthMetLabel.Visible = false;
            DoesNotMeetPasswordLengthLabel.Visible = false;
            NumberRequirementsMetLabel.Visible = false;
            DoesNotMeetNumberLabel.Visible = false;
            SymbolRequirementsMetLabel.Visible = false;
            DoesNotMeetSymbolLabel.Visible = false;
            LowercaseRequirementsMetLabel.Visible = false;
            DoesNotMeetLowercaseLetterLabel.Visible = false;
            CapitalRequirementsMetLabel.Visible = false;
            DoesNotMeetCapitalLetterLabel.Visible = false;
            PasswordIsValidLabel.Visible = false;
            PasswordInvalidLabel.Visible = false;
            //Create a passwordObject so we can keep track of all the pieces that were used to generate this password. Late we can recall these.

            PasswordParameters passwordObject = new PasswordParameters();

            //Symbols allowed to choose from
            List<char> symbolsAllowed = updateSymbolsAllowed();
            int seed = unchecked(DateTime.Now.Ticks.GetHashCode());
            Random rng = new Random(seed);

            List<char> requiredCapitalLetters = generateUppercase((int)CapitalLetterRequiredUpDown.Value,rng);
            List<char> requiredLowercaseLetters = generateLowercase((int)LowercaseLetterRequiredUpDown.Value,rng);
            List<char> requiredSymbols = generateSymbols((int)SymbolsRequiredUpDown.Value,symbolsAllowed,rng);
            List<char> requiredNumbers = generateNumbers((int)NumbersRequiredUpDown.Value,rng);

            int numberOfRandomsToGenerate = (int)PasswordLengthUpDown.Value - (int)(requiredCapitalLetters.Count + requiredLowercaseLetters.Count + requiredSymbols.Count + requiredNumbers.Count);
            List<char> randoms = generateRandom(numberOfRandomsToGenerate, symbolsAllowed, rng);
            List<string> allRandomCharacters = compressAllCharacters(requiredCapitalLetters, requiredLowercaseLetters, requiredSymbols, requiredNumbers, randoms);

            //Need to shuffle the random characters...

            string randomPassword = shufflePassword(allRandomCharacters, rng);
            GeneratedPasswordTextBox.Text = randomPassword;
            //store the password
            passwordObject = createPasswordObject(passwordObject, randomPassword);
            addItemToListBox(passwordObject);
        }