Random Password Generator [C#] 06-19-2013, 05:51 AM
#1
Hello guys, I've made a simple password generator which uses a list of strings to grab random chars and a random number generator that gives us the index numbers for those random chars in the string. Since you can't pick random char from string like in python E.g:
As I was unable to find a suitable function to do it in C#, but I did make an alternative, Here's my complete code:
Here's an example output of my program with Password length 15:
This is my first C# program so any suggestions will be appreciated
Regards,
Ex094
Code:
import random
items = 'abcdefghijklmnopqrstuvwxyz'
random.choice(items)As I was unable to find a suitable function to do it in C#, but I did make an alternative, Here's my complete code:
Code:
//Coded By Ex094
Random rnd = new Random(); //To Generate Random Numbers for string Index
string password = ""; //Variable to store the final Password
string passlist = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,./'[]~!@#$%^&*()_+=-|}{:?><";
Console.WriteLine ("Enter Password Length:");
string usrleng = Console.ReadLine(); //Get length from user in the form of string
int length = Convert.ToInt32(usrleng); //Convert the string to an int
for (int x = 0; x < length; x++) //Loop accroding to the length of the password
{
int pick = rnd.Next(1, passlist.Length); //Generate index number (Random)
password += passlist[pick]; //Get the random item from the passlist based on the random index number
}
Console.WriteLine("Your Generated Password Is: {0}", password); //Print the passwordHere's an example output of my program with Password length 15:
Code:
^CSFcogv5:{DhQ]This is my first C# program so any suggestions will be appreciated

Regards,
Ex094




![[+]](https://sinister.li/images/modern/collapse_collapsed.png)
![[Image: 2YpkRjy.png]](http://i.imgur.com/2YpkRjy.png)