PasswordCreator/frmCreatePassword.cs
/// <summary>
/// Create the password and save it to the file.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
Create the password and save it to the file.
Create the password and save it to the file .
private void btnCreatePassword_Click(object sender, EventArgs e)
        {
            int length;
            string name;
            string newPassword = "";
            bool specialChars = true;
            string[] passwordChars = new[]
            {
                "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz",
                "0123456789",
                "!$<>*+_"
            };  
            try
            {
                length = int.Parse(txtBoxPassowrdLength.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Value to Convert must be numeric.");
                txtBoxPassowrdLength.Focus();
                return;
            }
            if (length > 25)
            {
                MessageBox.Show("Value cannot be larger than 25 digits");
                txtBoxPassowrdLength.Focus();
                return;
            }
            if (length < 8) 
            {
                MessageBox.Show("Value should be at least 8 digits.");
                txtBoxPassowrdLength.Focus();
                return;
            }
            if (txtBoxName.Text != "")
                name = txtBoxName.Text.ToUpper();
            else
            {
                MessageBox.Show("Please enter a name for this password.");
                txtBoxName.Focus();
                return;
            }
            if (rdoBtnNo.Checked)
                specialChars = false;
            int oldPasswordCharsLineNumber = -1;
            Random myRandom = new Random();            
            for (int x = 0; x < length; x++) 
            {
                int passwordCharsLineNumber;               
                int passwordPosition = 0;
                if (specialChars)
                    passwordCharsLineNumber = myRandom.Next(passwordChars.Count());
                else
                    passwordCharsLineNumber = myRandom.Next(passwordChars.Count() - 1);
                oldPasswordCharsLineNumber = passwordCharsLineNumber;
                passwordPosition = GetSecureRandomNumber(0, passwordChars[passwordCharsLineNumber].Length - 1);
                char[] text = passwordChars[passwordCharsLineNumber].ToCharArray();
                newPassword += text[passwordPosition];             
            }
            pi.AddPassword(name, newPassword);
        }
private void btnCreatePassword_Click ( object sender , EventArgs e ) { int length ; string name ; string newPassword = " " ; bool specialChars = true ; string [ ] passwordChars = new [ ] { " " , " " , " " } ; try { length = int . Parse ( txtBoxPassowrdLength . Text ) ; } catch ( FormatException ) { MessageBox . Show ( " " ) ; txtBoxPassowrdLength . Focus ( ) ; return ; } if ( length > 25 ) { MessageBox . Show ( " " ) ; txtBoxPassowrdLength . Focus ( ) ; return ; } if ( length < 8 ) { MessageBox . Show ( " " ) ; txtBoxPassowrdLength . Focus ( ) ; return ; } if ( txtBoxName . Text != " " ) name = txtBoxName . Text . ToUpper ( ) ; else { MessageBox . Show ( " " ) ; txtBoxName . Focus ( ) ; return ; } if ( rdoBtnNo . Checked ) specialChars = false ; int oldPasswordCharsLineNumber = - 1 ; Random myRandom = new Random ( ) ; for ( int x = 0 ; x < length ; x ++ ) { int passwordCharsLineNumber ; int passwordPosition = 0 ; if ( specialChars ) passwordCharsLineNumber = myRandom . Next ( passwordChars . Count ( ) ) ; else passwordCharsLineNumber = myRandom . Next ( passwordChars . Count ( ) - 1 ) ; oldPasswordCharsLineNumber = passwordCharsLineNumber ; passwordPosition = GetSecureRandomNumber ( 0 , passwordChars [ passwordCharsLineNumber ] . Length - 1 ) ; char [ ] text = passwordChars [ passwordCharsLineNumber ] . ToCharArray ( ) ; newPassword += text [ passwordPosition ] ; } pi . AddPassword ( name , newPassword ) ; }
Create the password and save it to the file.
Create the password and save it to the file .
//make sure we have a numeric value //Really??  A password longer than 25 chars? //at minimum passwords should be at least 8 digits long //we dont need to see if rdoBtnYes is checked since we default it to true already. //build the password //first thing to do is figure out what string of chars we are going to use from passwordChars   //now we know what line number we have use it to seed the  //Random number generator to get a secure random number //save the password to file
sender
object
None
e
EventArgs
None