Login Register






Random Password Generator [C#] filter_list
Author
Message
Random Password Generator [C#] #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:

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 password

Here'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 Smile

Regards,
Ex094
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply





Messages In This Thread
Random Password Generator [C#] - by Ex094 - 06-19-2013, 05:51 AM
RE: Random Password Generator [C#] - by joalessio - 08-26-2019, 10:18 PM