PDA

View Full Version : [VB] Offline Password Generator



Fiendly
12-12-2011, 07:17 AM
Hello Habboxers!


Recently 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!


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.




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:


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).


Dim t = Nothing



So for now our code should start to look like this:


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:


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.




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.


txtGen.Text = x



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


Next i



This would display our code. Now lets form our code and display what we have right now:


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.


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:


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:
http://img850.imageshack.us/img850/318/passwordg.png


Tutorial created and made by me on 29th August 2011 (+10GMT)

Note: I realised I never put this tutorial on this forum so I decided to just add it, this work is from scratch and is purely offline. While you can use other languages such as python, this requires no other programs to be used. It's complete all in one package provided that it's being used with VB. Let me know if you have any ideas regarding this.

I may add a download link sometime soon if you're lucky.

GoldenMerc
12-12-2011, 11:34 AM
Good tut, cheers

Thomas
12-12-2011, 03:49 PM
Personally don't see the need for the program, but nice tutorial none the less!

Fiendly
12-12-2011, 07:48 PM
Personally don't see the need for the program, but nice tutorial none the less!

I wanted this for my passwords and couldn't find a decent one so I pretty much decided to make it myself. Random chars programs can turn into other things too but hey, if you can't find it yourself - then why wait for someone else

Want to hide these adverts? Register an account for free!