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

.NET 

[VB] Offline Password Generator [TUT]

Hello HackForumers!

Today I've decided to release the tutorial and code for my home made offline password generator. This took me around 2 days to properly finish it (Would of been less than a few hours but decided to tamper with things). Now I'm proud to have created this. Firstly I'm going to start with the basics of the program, which code I actually had received and worked around.

What is needed for the form:
- Button (Change to btnGen)
- Button (Change label to btnClear)
- Label (Change to txtChar)
- Radio Button x 3 (Make their text for each, 7; 12; 24)
So one button is 7, the other 12 and the last 24.

This code is for those who wish to figure out the program for themselves otherwise for those who wish to see my version then continue on!
Code
Const chars = "^&*%"
        Dim r, i
        Dim x As String
            For i = 1 To 36
                Randomize()
                r = Int((Rnd() * 61) + 1)
                x = x & Mid(chars, r, 1)
            Next i
            MsgBox(x)

First, we need to set our characters. This is set just under the Public Class Form.

Code
Const chars = "CHARACTERS"
Replace CHARACTERS with whatever you'd like be generated. This will be used later on in the program (Refer to the above code that we're basing this program around).

Next we need to declare some variables in our button (btnGen) for purposes in the program. First declare r and i which will be used for variables. (r will be used for randomising and i for generating the numbers) and declare x as a string which will display the generated characters. Use this following code:
Code
Dim r,i
Dim x As String

Now I've gone a bit further which this will be used later on in the program (Which I'll post up a bit shortly). Declare t which will be our based number. However the program will run an error if t isn't set with anything, so I added the variable 'Nothing' to set for t (Which makes t equal to 0).
Code
Dim t = Nothing

So for now our code should start to look like this:
Code
Public Class Form1
Const chars = "CHARACTERS"

Private Sub btnGen_Click (blah blah blah)
Dim r,i
Dim x As String
Dim t = Nothing
End Sub
End Class

So there we have the basis for our foundation of the program. However we still need to develop the rest of the button. We need to set it so that at least one radio button must be clicked and if it is then we need to make sure that it is set to the right variable. Here is the code for doing these:
Code
If rd7.Checked = False And rd12.Checked = False And rd24.Checked = False And rdCust.Checked = False And mskCust.Text = "" Then
            MsgBox("No buttons have been selected!", MsgBoxStyle.Exclamation, "No buttons!") 'Checking if any buttons have been selected'
        Else
            If rd7.Checked = True Then
                t = 7
            ElseIf rd12.Checked = True Then
                t = 12
            ElseIf rd24.Checked = True Then
                t = 24
End If

Please do note that you should always add a validation technique when doing things like this otherwise your program could look a tad messy. Now onto the next part for our generator of the program.

Above we had our For i = 1 to 36 part. Ignore the 36 and we're going to change 36 to "t". This is to let our program how many characters the password will be. Now you can change the characters to how many you want but I'm just doing as a basis for me. I'm going to give a bit of code to you and then break it down.

Code
For i = 1 To t
                Randomize()
                r = Int((Rnd() * 61) + 1)

                x = x & Mid(chars, r, 1)

This code is the heart of our program. This is what generates the characters and randomises them to give us our password. Like I had said, For i = 1 To t, t is the maximum number of characters generated. Randomize() is self explained, but randomizes the characters. We're using r now for it to be generating the number of characters. Int refers to intergising the string. Rnd() refers to randomdize however the * 61 and the + 1, I don't understand completely (I got this part off Microsoft) but it fits with the program well.

x is being used to form the characters with the character length. Mid(chars, r, 1) refers to returning an amount of characters. (This would be the characters with the r for the length. However we need to display the characters so we use the label now.
Code
txtGen.Text = x

We also need to add next i for the program to properly function.
Code
Next i

This would display our code. Now lets form our code and display what we have right now:
Code
Public Class Form1
Const chars = "CHARACTERS"

Private Sub btnGen_Click (blah blah blah)
        Dim r, i
        Dim x As String = Nothing
        Dim t = Nothing

            For i = 1 To t
                Randomize()
                r = Int((Rnd() * 61) + 1)

                x = x & Mid(chars, r, 1)

            Next i
            txtGen.Text = x
        End If
    End Sub
End Class

Now since we have this we need to add a clear button to clear the form completely. I'll just drop the code in here as there's not that much to do with this.
Code
If txtGen.Text = "" And rd7.Checked = False And rd12.Checked = False And rd24.Checked = False Then
            MsgBox("Form is already cleared!", MsgBoxStyle.Exclamation, "Cannot clear!")
        Else
            txtGen.Text = ""
            mskCust.Text = ""
            rd7.Checked = False
            rd12.Checked = False
            rd24.Checked = False
            rdCust.Checked = False
            MsgBox("Cleared form!", MsgBoxStyle.Exclamation, "Form cleared!")

Now our full code should look like this:
Code
Public Class Form1
Const chars = "CHARACTERS"

Private Sub btnGen_Click (blah blah blah)
        Dim r, i
        Dim x As String = Nothing
        Dim t = Nothing

            For i = 1 To t
                Randomize()
                r = Int((Rnd() * 61) + 1)

                x = x & Mid(chars, r, 1)

            Next i
            txtGen.Text = x
        End If
    End Sub

Private Sub btnClear_Click (blah blah blah)
        If txtGen.Text = "" And rd7.Checked = False And rd12.Checked = False And rd24.Checked = False Then
            MsgBox("Form is already cleared!", MsgBoxStyle.Exclamation, "Cannot clear!")
        Else
            txtGen.Text = ""
            mskCust.Text = ""
            rd7.Checked = False
            rd12.Checked = False
            rd24.Checked = False
            rdCust.Checked = False
            MsgBox("Cleared form!", MsgBoxStyle.Exclamation, "Form cleared!")
        End If
End Sub
End Class

And that's there is to it!
In my program, I have added more features like copy and paste functions as well as writing to a text file.. However I would like you to figure that so you can develop your potentials as VB programmers!

My program screen shot:
[IMG]http://img850.imageshack.us/img850/318/passwordg.png[/IMG]

Tutorial created and made by Lenneth on 29th August 2011 (+10GMT)
can you please provide a direct download link to the source code ?
Men good work This better than a aource :D
(Aug 29, 2011 09:46 AM)rAtoN Wrote:  Men good work This better than a aource :D

Seriously L2Speak, I don't even know how someone speaks engrish as bad as you do. It's just terrible.
(Aug 29, 2011 10:29 AM)N3bco Wrote:  Seriously L2Speak, I don't even know how someone speaks engrish as bad as you do. It's just terrible.

It's English, not "engrish".

http://elitevs.net/download.php?i=1&s=1

Kthxbaii.
(Aug 29, 2011 06:52 AM)DEATH STAR X Wrote:  can you please provide a direct download link to the source code ?

Getting a source code won't properly help you develop the program, however the code I gave pretty much is a summed up version of my program. All you'd need to do is slap in some radio buttons, buttons and a textbox and put in the code (Without the shortcuts of the button codes) and the program will be fully functional.

What I've added is what I've learnt, if needed I can post up the source code and give the whole thing. But PM me if you want it if you're slack at learning.
So why in the hell would this ever need to be, "online."
(Aug 29, 2011 05:35 PM).bLaZeD Wrote:  So why in the hell would this ever need to be, "online."
Good point, maybe to have a nice feature while you can surf on google from the program while generating password lolz.
(Aug 29, 2011 05:35 PM).bLaZeD Wrote:  So why in the hell would this ever need to be, "online."

I called it the 'Offline Password Generator' for the desktop. There are many 'online' versions using PHP so I thought why not make a desktop where you don't need to use PHP or any other language to do this on the internet. Good question though 🤝
(Aug 29, 2011 05:35 PM).bLaZeD Wrote:  So why in the hell would this ever need to be, "online."

Most password generators are PHP based and the executable's just do a call to the PHP site.

This is entirely offline :)
When I can, I'll write up a few more tutorials that I have worked on.
Hope some people will learn from this :)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Snowdrop14Jan 19, 2016 06:41 PM 4 400 Jan 19, 2016 06:41 PM
Last Post: horrorland1
[.NET] by Gr0wlitJun 6, 2013 07:19 AM 46 2,196 Jun 6, 2013 07:19 AM
Last Post: RXDs
[.NET] by PsychotiicAug 2, 2012 01:22 PM 22 869 Aug 2, 2012 01:22 PM
Last Post: ident