Thursday 6 October 2011

How To Create A Simple Key Generator In Visual Basic 2010 FOR BEGINNERS

Microsoft Visual Basic 2010 is a very powerful tool that allows you to quickly and easily set up the design of a program and just as easily allows you to code your program. It has been used to make anything from simple text editors to advanced and powerful operating systems. Today I am going to show you how to create a Password, PIN, and Key generator that should look something like this when we are done. I will also teach you how to customize it and make it your own.







Before we start I would like to explain this will not help you crack, hack, or attack accounts, personal information, or programs. It simply will give you a randomly generated password, PIN, or serial key.
*If you already have Visual Basic skip to Starting your Generator
Downloading and Installing Visual Basic 2010
1)Follow this link to Microsoft Visual Basic 2010 Express

Download: http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-basic-express


*English speakers click this button:



*Non-English Speakers go here:



2)Click install now and let the download run. You will be asked to allow it to make changes to your computer. Make sure you click yes.
*It is 100% safe see here:




3)Once the download is complete, complete the installation process and you are ready to go.
Starting your Generator
Now that our installation is complete we are going to start our generator. First you need to open up visual basic and create a new Windows Forms Application. To do this go to File>New>Windows Forms Application. Usually when you start a visual basic project I suggest getting the style and look of your project done first. That is what we are going to do here.
First, we will create our text boxes and labels that will show the generated code. We will create 1 big text box for Passwords, 1 big text box for PINS, and 6 small text boxes for Keys. Text boxes are located in the tool box under Common Controls right here:




Labels are located in the toolbox also under Common Controls right here:



You can insert these textboxes and labels where ever you’d like and you can resize and format your page however you like. When you are done your page should look something like this:




Please take note the room I left at the top for things like Logos or anything extra you’d like to add and the room I left at the bottom for all your buttons.
Ok so now that our textboxes and labels are all in place we are going to add buttons that, when clicked, will generate the different codes. Buttons are located in the tool box under Common Controls right here:

In my generator I had several buttons. However to keep this tutorial simple we are only going to have 3. These 3 buttons will say “Generate Password”, “Generate PINS”, and “Generate Keys”. You can add however many you like but if you are following along with the tutorial your buttons should look something like this





Now that all your simple necessary display setups are done, it’s time to add some style to this. I am going to add my BMC Generator picture made with Photoshop, and I am going to change the background to red. To add a banner logo to your picture first you must go to Common Controls and find Picture Box. You can easily control the size of the picture box and the picture you want in it. Simply use the properties tab in the bottom right corner of your VB Document. Now to change the background color, click on the outside of your form and go to properties. There you will find a background color tab. There you can change it to whatever you want. Mine now looks like this:




There you go! You are all done with creating the basic visual part of your generator! Now it’s time to code it!
Coding the Buttons
To make our generator work we are going to need to code 3 different functions. 1 for passwords, 1 for pins, and 1 for keys. This is because each one contains different material. To see the coding of your VB project double click on any button and the form will pop up. Now let’s create our passwords function using this code:
*Note this goes right underneath Public Class. It cannot go in a private sub.
Public Function GeneratePasswordCode() As Object
Dim intRnd As Object
Dim intStep As Object
Dim strName As Object
Dim intNameLength As Object
Dim intLenght As Object
Dim strInputString As Object
strInputString = “1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”
intLenght = Len(strInputString)
intNameLength = 10
Randomize()
strName = “”
For intStep = 1 To intNameLength
intRnd = Int((intLenght * Rnd()) + 1)
strName = strName & Mid(strInputString, intRnd, 1)
Next
GeneratePasswordCode = strName
End Function
In this function there are 3 crucial things you should pay attention to. They are, the name of the function (GeneratePasswordCode( ) ), strInputString, and intNameLength. The name of the function is important because we are going to use it to call the function later in our coding. strInputString displays all the characters we are going to use to make the random password, and the intNameLength sets how many characters long it is going to be. You can customize these functions by simply changing them around and playing around with them!
To create our pin generator function we are going to do the same thing except we are going to change the function name to GeneratePINcode( ), make the strInputString=”1234567890”, and we are going to make the input length at 4. You can make it however long you want but typically pins are 4. Your code should now look like:
Public Function GeneratePINSCode() As Object
Dim intRnd As Object
Dim intStep As Object
Dim strName As Object
Dim intNameLength As Object
Dim intLenght As Object
Dim strInputString As Object
strInputString = “1234567890″
intLenght = Len(strInputString)
intNameLength = 4
Randomize()
strName = “”
For intStep = 1 To intNameLength
intRnd = Int((intLenght * Rnd()) + 1)
strName = strName & Mid(strInputString, intRnd, 1)
Next
GeneratePINSCode = strName
End Function
Now let’s create our Keys function. Do the same as you did with the PINS, but add the alphabet in all caps to strInputString and make the intNameLength=6. The reason we are making it equal 6 is because we are using 6 different text boxes, so if we put it as 25 it will put 25 digits in each individual text box. Your code should now look like:
Public Function GenerateKeysCode() As Object
Dim intRnd As Object
Dim intStep As Object
Dim strName As Object
Dim intNameLength As Object
Dim intLenght As Object
Dim strInputString As Object
strInputString = “1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ”
intLenght = Len(strInputString)
intNameLength = 6
Randomize()
strName = “”
For intStep = 1 To intNameLength
intRnd = Int((intLenght * Rnd()) + 1)
strName = strName & Mid(strInputString, intRnd, 1)
Next
GenerateKeysCode = strName
End Function
Now all your functions are ready to go. It’s time we put them to use! First we are going to create a click event. This means that when a user clicks something happens. To do this double click Generate Passwords. You have just created your first click event. Now in between Private Sub and End Sub put:
Textbox#.text=GeneratePasswordCode( )
This is calling our function to the textbox we are using and making it generate a random code. Make sure you put the textbox number where I put the # symbol or else nothing will happen.
You can do the same exact thing for pins except it will be:
Textbox#.text=GeneratePINSCode()
It’s the same thing just a different name.
Now for Keys it’s a little more work because we have 6 different textboxes so your code will look more like:
Textbox#.text=GenerateKeysCode()
Textbox#.text=GenerateKeysCode()
Textbox#.text=GenerateKeysCode()
Textbox#.text=GenerateKeysCode()
Textbox#.text=GenerateKeysCode()
Textbox#.text=GenerateKeysCode()
It’s the same thing just 6 times!
Now your program is finished! Run and Debug the program to make sure there are no errors! Then go to Build>Publish and complete the process. Then you should get an icon on your desktop called setup.exe. Run that and install your application and pass it on to all your friends!

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
x

Get Our Latest Posts Via Email - It's Free

Enter your email address:

Delivered by FeedBurner