Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Secure Password Generator [Re-vamped] [Updated 12/29/2016]

I've had this project laying around awhile I made for a friend to further understand something (I don't recall anymore). Feel free to use this for account creators, login systems, etc. Ask any questions! I'm sorry I do not really comment my code.

GUI

[Image: adef7d6d87.png]

Password Generator Class
Spoiler (Click to View)

Secure Random Class
Spoiler (Click to View)

Usage
Spoiler (Click to View)

Project Source Download

Changed (12/29/2016)
  • Changed While Loop to For Loop.

  • Used StringBuilder.

  • Removed Math.Floor.

  • Removed issue with byte buffer being created every time.

  • Updated download link to new project source.


Your code is very nice, however I do have one gripe with it.
You use a while loop to select characters randomly based off of your RNG. This is a lot more hassle and uses more resources, and is a messier solution.
Instead, what you could do is:
Code
StringBuilder charPoolBuilder = new StringBuilder();
if (UpperCase) charPoolBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
// ... etc
StringBuilder myPassword = new StringBuilder();
for (int i = 0; i < passwordLength; i++) myPassword.Append(charPoolBuilder[RND.Next(charPoolBuilder.Length)]);
return myPassword.ToString();

This way, instead of doing twice the selection & having a messy case selection, you have a "one size fits all" solution. Now, if you wanted to add European characters (eg éíúóá), you could do so by doing
Code
if (European) charPoolBuilder.Append("éíúóá");
rather than having an extra case statement. Otherwise, your code is great and a great learning point to others about CSPRNGs.
New to trading cryptocurrencies but don't know where to start? Join Binance here! Binance is my favourite exchange for cryptocurrencies w/ low fees.

[Image: 793854efd3c9ee7d90ddd413ae9deed6.png]
Pull Request for PasswordGenerator class

PHP Code

<?php 
while (password.Length < 12) 

Should be:

PHP Code

<?php 
while (password.Length < Length) 

If you change this you can do this:

PHP Code

<?php 
string password 
= pGenerator.Generate(12) //12 being the length
string password2 = pGenerator.Generate(15) //15 being the length
string password3 = pGenerator.Generate(25) //25 being the length 
I'm confused, you have a box to choose the length but it's hard-coded to 12?
[Image: serversig.gif]
I mean, nice contribution but what's the point when I can use a web-based generator?
(Dec 20, 2016 01:12 PM)Kaspah Wrote:  I mean, nice contribution but what's the point when I can use a web-based generator?

Are you retarded? He's making a contribution so that others can learn from it.
New to trading cryptocurrencies but don't know where to start? Join Binance here! Binance is my favourite exchange for cryptocurrencies w/ low fees.

[Image: 793854efd3c9ee7d90ddd413ae9deed6.png]
(Dec 20, 2016 01:12 PM)Kaspah Wrote:  I mean, nice contribution but what's the point when I can use a web-based generator?

I think he gave a pretty good example in the OP. "Feel free to use this for account creators"
[Image: serversig.gif]
(Dec 20, 2016 01:06 PM)Zilog80 Wrote:  Pull Request for PasswordGenerator class

PHP Code

<?php 
while (password.Length < 12) 

Should be:

PHP Code

<?php 
while (password.Length < Length) 

If you change this you can do this:

PHP Code

<?php 
string password 
= pGenerator.Generate(12) //12 being the length
string password2 = pGenerator.Generate(15) //15 being the length
string password3 = pGenerator.Generate(25) //25 being the length 

Oh shit! My bad. I forgot to remove that. I was testing and forgot to remove that part. I'll fix it now.
Very nice, this "Friend" of yours must have been something really special.
Anyways, Good contribution to the community!
(Dec 22, 2016 12:40 PM)passwords Wrote:  Very nice, this "Friend" of yours must have been something really special.
Anyways, Good contribution to the community!

Why the hostility? It was someone on Skype wanting to learn about ListView/ListBox and Random String generation. So I threw this project together and added a little more to it to post on here.

EDIT: God damn it. DOT1 was the friend I made it for. Lmfao. You dick. Haha.
Just some things to think about:

  1. Empty constructors can be omitted.

  2. StringBuilder is more efficient when... building a string. (Click to View)

  3. Decimal/float/double to int cast will drop the decimals, so no need for the extra Math.Floor.

  4. Creating a new byte buffer for every random number is quite costly. (Click to View)


Lotta blood to let, peace to make, give a fuk about a check
  • Empty constructors can be omitted. - This seems extraordinarily picky..more like one of your pet-peeves.

  • StringBuilder is more efficient when... building a string. (Click to View) - Yea, that was my bad. I was having issues (brain fart) when using StringBuilder and resorted to concatenations. Never bothered to revert back.

  • Decimal/float/double to int cast will drop the decimals, so no need for the extra Math.Floor. - Didn't know that. Thank you!

  • Creating a new byte buffer for every random number is quite costly. (Click to View)



I would love and greatly appreciate whatever you use to benchmark. It would come in handy for future projects.
I just made one of these myself using very similar methods, great work. All improvements are done with practice and time.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by VentriloquismFeb 12, 2018 07:54 AM 20 1,198 Feb 12, 2018 07:54 AM
Last Post: Dialog
[.NET] by debugFeb 19, 2016 05:30 PM 44 1,312 Feb 19, 2016 05:30 PM
Last Post: debug
[Python] by Snowdrop14Jan 19, 2016 06:41 PM 4 401 Jan 19, 2016 06:41 PM
Last Post: horrorland1