Foxy1986

GUI password generator

Sep 25th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.00 KB | None | 0 0
  1. //GUI password generator
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12.  
  13. namespace Password_Generator
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         public int numVal;
  18.         public string completed_password;
  19.         public bool includeUpper = false, includerSpecial=false, includeNumbers=false;
  20.  
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.         }
  25.  
  26.         private void button1_Click(object sender, EventArgs e)
  27.         {
  28.             results_textBox1.Text = "";
  29.  
  30.             Char[] alphabet = new Char[] {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
  31.             Int32[] numbers = new Int32[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  32.             Char[] special = new char[] { '!', '£', '$', '#', '&', '@', '%' };
  33.            
  34.            
  35.             try
  36.             {
  37.                numVal= Convert.ToInt32(length_textBox1.Text);
  38.             }
  39.             catch (FormatException ex)
  40.             {
  41.                 MessageBox.Show("The length needs to be a NUMBER idiot!");
  42.                 length_textBox1.Clear();
  43.             }
  44.  
  45.             Random rnd = new Random();
  46.  
  47.             for (int i = 1; i <= numVal; i++)
  48.             {
  49.  
  50.                 //upper?
  51.  
  52.                 if ((i == 2 || i == 5) && includeUpper)
  53.                 { completed_password += alphabet[rnd.Next(1, 25)].ToString().ToUpper(); }
  54.  
  55.                 //special?
  56.  
  57.                 else if ((i == 1 || i == 3) && includerSpecial)
  58.                 { completed_password += special[rnd.Next(1, 6)].ToString(); }
  59.              
  60.                 //nums?
  61.  
  62.                 else if ((i == 4 || i == 8) && includeNumbers)
  63.                 { completed_password += numbers[rnd.Next(1, 9)].ToString(); }
  64.                            
  65.  
  66.                else { completed_password += alphabet[rnd.Next(1, 25)].ToString(); }
  67.  
  68.             }
  69.  
  70.             results_textBox1.Text += completed_password;
  71.             completed_password = "";
  72.  
  73.         }
  74.  
  75.         private void textBox1_TextChanged(object sender, EventArgs e)
  76.         {
  77.          
  78.         }
  79.  
  80.         private void button1_Click_1(object sender, EventArgs e)
  81.         {
  82.             Clipboard.SetText(results_textBox1.Text);
  83.             MessageBox.Show("Copied");
  84.         }
  85.  
  86.         private void upper_checkBox1_Checked(object sender, EventArgs e)
  87.         {
  88.             MessageBox.Show("Blah");
  89.         }
  90.  
  91.         private void timer1_Tick(object sender, EventArgs e)
  92.         {
  93.             if (upper_checkBox1.Checked) includeUpper = true;
  94.             else includeUpper = false;
  95.  
  96.             if (special_checkBox1.Checked) includerSpecial = true;
  97.             else includerSpecial = false;
  98.  
  99.             if (numbers_checkBox1.Checked) includeNumbers = true;
  100.             else includeNumbers = false;
  101.  
  102.  
  103.  
  104.         }
  105.     }
  106. }
Add Comment
Please, Sign In to add comment