Please consider donating: https://www.corelan.be/index.php/donate/


2,375 views

Free Tool – Password Generator dll for Visual Studio (and other languages)

Because some of my own applications required the ability to create random passwords, I decided to write a small dll that will allow me to implement the generation of random passwords in a fast and easy way.

You can download the dll from
PVEPasswordGenerator.dll (20.0 KiB)

How to use the dll in Visual Studio

Create a new Visual Studio project.  In my example below, I’ve used a Windows Console application in C#, but you can use the dll in any Visual Studio project.

Click “Project” – “Add reference”. Open the “Browse” tabsheet and browse to the dll file. Select the dll file and click “OK” to add the reference to your project.

You should now see a reference to the dll in the Visual Studio Solution Explorer.

image_2

The simple console application that demonstrates some of the possibilities of the password generator looks like this :

using System;
using System.Collections.Generic;
using System.Text;

namespace RandomPW_Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("\nFull character set passwords :");
            for (int i = 0; i < 15; i++)
            {
                //create password will all character groups
                Console.WriteLine(PVEPasswordGenerator.GeneratePassword(20));
            }
            Console.WriteLine("\nLowercase passwords :");
            for (int i = 0; i < 15; i++)
            {
                //create lowercase passwords only
                Console.WriteLine(PVEPasswordGenerator.GeneratePassword(20, true, _
                     false, false,false));
            }
            Console.WriteLine("\nUppercase passwords :");
            for (int i = 0; i < 15; i++)
            {
                //create uppercase passwords only
                Console.WriteLine(PVEPasswordGenerator.GeneratePassword(20, false, _
                    true, false, false));
            }
            Console.WriteLine("\nPasswords with numbers and special characters :");
            for (int i = 0; i < 15; i++)
            {
                //create passwords with numbers and special characters
                Console.WriteLine(PVEPasswordGenerator.GeneratePassword(20,false,_
                  false,true,true));
            }
        }
    }
}

The output of the console application looks like this :

Full character set passwords :
6P4Z8SrfwiFx7m3Rs09T
DR3qZJ4jtxBXon82961P
9P2L0TmxgeXf1q3Mc67A
9QMP8pmnkcZ7B26fj03Y
nQNZ0bAo8Hke732WisX1
FEjtW92eSx18QL4r57zR
qj37wKM2m6Ld5eTBFS4t
0Z1R5WjnMt2d8o6Ez3fY
fmigD8E962qXnBN75FWr
3rSgHwi9cxAy07WP682D
XgH8xi54r0E2Z9JmNS3f
FYpS524d7Hr9DX1axjZ8
4rd8k1f673b0CFRjWDPi
9k0jXWb3a5Aw7cNB8C6f
6iL9kfe48Xay25MHDpT1

Lowercase passwords :
azykednfjpbcimwosxtg
kpomfdzganybjreqstic
jrpwfnxcmbyagqdsztoe
aksmzewxtijqpncfrobd
rictamjxqpdgyksnwzfb
agdemnwzjpkyxsoqtcir
xpdckamtbgfyrenqisjz
srwbmeyqtfzoanijdcgp
psoykjxzgmdbqcrfiwat
qntmzkxfpjawieocrdsg
qjcgtiwebymsoxzfnkdr
tbpwknazejcsmdgrqxyi
eidamwpgsjnftrzqykox
adjopbwmetxyinfgrqzc
kgebzpmadjtnoxwrsqic

Uppercase passwords :
WXRGKPSNJYMEZLBFCTDH
ATCEHXSJQFWDNBRZPLKM
TWBASQHFERPMCZLJXDYG
QZWADLNXHGFCEJKSRMBP
PRBMTFWYLZSXGQEDJHAN
NTWXFRGDBPASYQEHMLJZ
YADSPLZQFJKWEXMBRHGN
ZEFLGMTDKCBJYAWQXPNR
JKQDHSTMYRBCPNAWLEZF
PHNSLJYZFBQMADWRCEXK
BAFNLWJPEHQRDGSXKYCM
ZHQYNEBFGTCDSRKLMPAW
SBXNZKHWCAQFTDPYJLME
SRNKZYDFLBCAHWGMTXQP
QHKXMSPALWJTGEZFRYCN

Passwords with numbers and special characters :
37$@19&:50;]8=%642,_
32#+98];06}/1&|574,&
46&{57?&18<_2$%309#,
08{!65*[97_.2-<134?]
85<_36&?10+*2}>749@]
28|@13._96<;0+*547}&
52$/17;?34[%0]:968!&
35[.26],78|}1:!094%$
57<-26[}09]&1&$384>?
86$<39/|=0%}215];
72?!36;+04}|5*[198]>
69!{21;>54}+7%[308?|
61_;43.#87*{9?&052!,
45@!18{#73:-6%=902$]
31?/64[-57];9_=082%+

The GeneratePassword() function takes up to 5 arguments :

Type Variable Description
int NrOfCharacters This variable allows you to define the length

(number of characters) of the password.

Boolean UseLowerCaseCharacters True or False.  If set to True, the password

will contain lowercase characters

Boolean UseUpperCaseCharacters True or False.  If set to True, the password

will contain uppercase characters

Boolean UseNumbers True or False. If set to True, the password

will contain numbers

Boolean UseOtherCharacters True or False. If set to True, the password

will contain special characters

Character sets :

Lower Case abcdefghijklmnopqrstuvwxyz
Upper Case ABCDEFGHIJKLMNOPQRSTUVWXYZ
Numbers 0123456789
Special Characters *$-+?_&=!%{}/[]@#&|:;,.<>

If you launch the function without any parameters, a password of 8 characters will be created, using all character sets.

The dll works fine for me, but if you encouter bugs or strange behaviour, let me know.

Using custom character sets

You can use your own character set by setting some variables prior to generating the password.

These 4 variables are :

image_4

(string) PW_CHARS_LCASE

(string) PW_CHARS_UCASE

(string) PW_CHARS_NUMERIC

(string) PW_CHARS_SPECIAL

In C#, this is how you can set or get the values of those variables :

Console.WriteLine("\nCurrent lcase character set is : " + PVEPasswordGenerator.PW_CHARS_LCASE);
Console.WriteLine("\nLowercase password, but with limited character set of abcde");
PVEPasswordGenerator.PW_CHARS_LCASE = "abcde";
for (int i = 0; i < 15; i++)
{
  Console.WriteLine(PVEPasswordGenerator.GeneratePassword(20,true,false,false,false));
}
//set all new characters
PVEPasswordGenerator.PW_CHARS_LCASE = "abc";
PVEPasswordGenerator.PW_CHARS_UCASE = "ABC";
PVEPasswordGenerator.PW_CHARS_NUMERIC = "012";
PVEPasswordGenerator.PW_CHARS_SPECIAL = "-+?";

Console.WriteLine("\nFull character set passwords, with limited set of characters");
for (int i = 0; i < 15; i++)
{
   Console.WriteLine(PVEPasswordGenerator.GeneratePassword(20, true, true, true, true));
}

The output of these 2 iterations looks like this :

Current lcase character set is : abcdefghijklmnopqrstuvwxyz

Lowercase password, but with limited character set of abcde
bbadddeacadecebcceab
dcdabcecbeabacaeeddb
cdbaecdbbaeeccadabed
aaaeecebdbcdddacecbb
dacbcceebbdaebdcedaa
bbdeabdcaadccabeedce
edcedbdeaacbbacecabd
eddbaaaeebbcecdcdcab
cdeacdbaaecabbeeddbc
dbdcacaeabeedabccedb
aacadabddcbdbecceeeb
beeabcedaddcdbccaeba
ebaebedddccaccaebdab
cccbdabeeaadadcdeebb
cdeadadbeeabcdbcaebc

Full character set passwords, with limited set of characters
?C-a+-c1bB12B2A?bc0A
1+-aA0cBB?0C12Ccbb?+
cb2+01-aC0?AAcB1?-aC
?+bCaCb-cAA0-1?2cB02
cCA-b1?a2A?-10ac0+BC
+?cAacB2bCB0+2-0bC1-
-b0ac1bBC0?c+A-2AB1+
+A+12C0c0B?1CBbaa-c?
bC?A2a-C02-BBb1a?+c1
2bBc1?Bb2ACaa?0++A-1
1A2-B-Ba0C+c?cCb?1a0
2-A?2Cb?+0aB-caAbC11
220BaA-cbB01??+c-aCC
A2B-cC00AaC?2+1c-b?b
101+cBa?abcC?+2BAA2-

Note : In case you were wondering : the dll does not use the default Windows randomizer, which is based on the current time. (So if you use that randomizer, all random functions within the same second will return the same value.). In fact, my dll uses a random seed (and not the current time), and the string that results from the password generator routing is then scrambled again.

© 2008 – 2021, Peter Van Eeckhoutte (corelanc0d3r). All rights reserved.

Comments are closed.

Corelan Training

We have been teaching our win32 exploit dev classes at various security cons and private companies & organizations since 2011

Check out our schedules page here and sign up for one of our classes now!

Donate

Want to support the Corelan Team community ? Click here to go to our donations page.

Want to donate BTC to Corelan Team?



Your donation will help funding server hosting.

Corelan Team Merchandise

You can support Corelan Team by donating or purchasing items from the official Corelan Team merchandising store.

Protected by Copyscape Web Plagiarism Tool

Corelan on Slack

You can chat with us and our friends on our Slack workspace:

  • Go to our facebook page
  • Browse through the posts and find the invite to Slack
  • Use the invite to access our Slack workspace
  • Categories