Post: Random Password Generator (Download & Source)
08-07-2014, 04:44 PM #1
Default Avatar
Brad
Guest
(adsbygoogle = window.adsbygoogle || []).push({}); This one one of my first main attempts at making a program in C# after having experience with PHP and Javascript. Here I have made a random password generator.

You must login or register to view this content.

Source
    
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
if (letters.Checked == true || specialcharacters.Checked == true || numbers.Checked == true)
{
GeneratePassword();
}
else
{
alertMessage(3);
}

}

private void GeneratePassword()
{
List<string> CheckedBoxes = new List<string>();

if (letters.Checked) CheckedBoxes.Add("letters");
if (specialcharacters.Checked) CheckedBoxes.Add("specialcharacters");
if (numbers.Checked) CheckedBoxes.Add("numbers");
string[] CheckBoxes = CheckedBoxes.ToArray();

string GeneratedString = "";

Random random = new Random();
char[] alphas = "dFoQBNTfDeRmrHiUlSzCVJWLKcqXwOxEnMbsazkpYPhjtgIuZGyA".ToArray(); // Alphabet, lower and upper
char[] specChar = "!£$%^&*()_+-={}[]Angry~;'#<>,.?/".ToArray();
int ran;

for (int i = 0; i < password_length.Value; i++)
{
ran = random.Next(1, 1+CheckBoxes.Length);
//Console.WriteLine(CheckBoxes[ran-1]);

switch (CheckBoxes[ran-1])
{
case "letters":
ran = random.Next(1, alphas.Length);
GeneratedString += alphas[ran-1];
break;
case "numbers":
ran = random.Next(0, 10);
GeneratedString += ran;
break;
case "specialcharacters":
ran = random.Next(1, specChar.Length);
GeneratedString += specChar[ran - 1];
break;
}
generated_password.Text = GeneratedString;
}
}

private void label3_Click(object sender, EventArgs e)
{
if (generated_password.Text != "")
{
System.Windows.Forms.Clipboard.SetText(generated_password.Text);
alertMessage(1);
}
else
{
alertMessage(2);
}
}

public void alertMessage(int id)
{
switch (id)
{
case 1:
MessageBox.Show("Password Copied To Clipboard", "Information..", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
break;
case 2:
MessageBox.Show("No Content To Copy To Clipboard", "Information..", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
break;
case 3:
MessageBox.Show("Please Select a Checkbox", "Information..", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
break;
}
}
}
}



Program Download:
You must login or register to view this content.
Source Download:
You must login or register to view this content.
Last edited by Brad ; 08-07-2014 at 05:18 PM.

The following 6 users say thank you to Brad for this useful post:

John, Dan, Pichu, SiLLiKaLaX
08-09-2014, 06:36 AM #11
Pichu
RIP PICHU.
Originally posted by Brad View Post
Thanks for the feedback! I'm more then happy to see how you'd go around this! Have you got skype?


Sorry, I'm really really tired but here is a quick example: You must login or register to view this content.

I didn't feel like writing the appropriate loop logic so I just used a simple Goto although a while loop likely would be better for that case.

I might come back tomorrow and clena it back up but that should be somewhat of an example of what I meant.

There is a lot more in the one I wrote because it includes more difficult combinations as well. Feel free to PM me with questions.

I might actually just wrote an appropriate tutorial for it, with the goto crap removed lol.

Oh, I also used a combobox...
Last edited by Pichu ; 08-09-2014 at 06:38 AM.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo