Sinisterly
Random Password Generator [C#] - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework)
+--- Thread: Random Password Generator [C#] (/Thread-Random-Password-Generator-C)



Random Password Generator [C#] - Ex094 - 06-19-2013

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


RE: Random Password Generator [C#] - Deque - 06-19-2013

Nice snippet. Now to make this safe you can collect some entropy before using a pseudo number generator. I am not sure how hard that is, I have never done it before. But I think you might find something on the web.

Edit: I already found something: http://upokecenter.dreamhosters.com/articles/2011/04/entropy-source-random-seed-generator-in-c/


RE: Random Password Generator [C#] - Ex094 - 06-21-2013

@Deque Thank you and that is a good resource you provided there bookmarked, May I ask if there's any pseudo code for that code (IN the resource site) I'm having a little problem understanding the code

Edit: Entropy is indeed an excellent thing introduced in Information theory, this really caught my attention and is really interesting Smile Thanks for pointing this deque! Cheers


RE: Random Password Generator [C#] - Deque - 06-22-2013

(06-21-2013, 05:01 AM)Ex094 Wrote: @Deque Thank you and that is a good resource you provided there bookmarked, May I ask if there's any pseudo code for that code (IN the resource site) I'm having a little problem understanding the code

No, it is just a source sample. The missing indentation makes it hard to read.


RE: Random Password Generator [C#] - joalessio - 08-26-2019

e possibile testare grazie