Jump to content

How to make a Password Generator

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
CriticalError

CriticalError

    Newbie

  • Members
  • PipPipPip
  • 42 posts
Hello Programmers!

This is my first ever tutorial so apologies if there are any mistakes.


Well we got a lot to go through lets get started!

This will be split in to two (2) Parts A and B

Part A will be Design

and Part B will be coding



(Important things are highlighted in bold)

PART A - DESIGN

Make your PasswordGenerator (PW) about 329, 261 In height and width

insert:

1) Menustrip

2) Button

3) 3 Checkboxes

4) 2 Labels

5) Textbox

6) NumericUpdown

7) Progress bar

Now lay them out as shown in the image below and name them as shown.

(NB: Don't; change the actual names of the objects leave them default e.g button1 only change display name, unless you know what your doing.)

Also where it says "File" under Menu-strip-one click it and put a "Save" under it

Now click Textbox1 hit the Triangle in he top right hand corner and make it double line. Then in it's properties set it to Readonly and ScrollBars Both

Attached File  PWGEN full image..JPG   25.72K   697 downloads

OK Now we have done that lets change the behaviour of the PW.
Attached File  Capture2..JPG   56.1K   419 downloads

OK click outside of the border of Form1. Lets change it's Text to PasswordGenerator. Second

where it says MaximiseBox make this False

Then scroll to top of the properties and where it says FormBorderStyle this will be Fixed3D or anything of your choice.

OK we are done here.

PART B - CODING

One - Double Click Form 1

Enter this code:

' This will make label2 text show as nothing you will understand why later
Label2.Text = ""

Two - Double click File>Save

Enter this Code:

Now notice the dlg.filter you can add more file types if you like
the dlg.InitialDirectory is the directory the save-dialog will open up and show.

   Using dlg As SaveFileDialog = New SaveFileDialog

            dlg.Title = "Save"

            dlg.Filter = "Rich Text Files (*.rtf)|*.rtf|Html File (*.html)| *.Html|Text File (*.txt)|*.txt"

            dlg.CheckPathExists = True

            dlg.InitialDirectory = "C:\"

            dlg.DefaultExt = "txt"

            Dim myReturn As DialogResult = dlg.ShowDialog()


            If System.Windows.Forms.DialogResult.OK.Equals(myReturn) Then

                System.IO.File.WriteAllText(dlg.FileName, TextBox1.Text)

            End If

        End Using

Thrid - Double Click Button one and insert this. ( I have annotated this with comments ''')

NumericUpDown1.Text.Trim()

        If CheckBox1.Checked = False And CheckBox2.Checked = False And CheckBox3.Checked = False Then

            MsgBox("You Must Select A Method ", MsgBoxStyle.Critical) 'You can always change your message

        End If

        

        If Val(NumericUpDown1.Text) <= 3 Then 'You can change the minimum number

            MsgBox("Please enter a number higher than three", MsgBoxStyle.Critical, )

            Exit Sub 'You can change your mwssage


        End If

        If Val(NumericUpDown1.Text) > 78 Then 'You can change the maximum number.

            MsgBox("number is too high max 78", MsgBoxStyle.Critical, )


            Exit Sub


        End If

        TextBox1.Text = GenerateCode()

    End Sub

    Public Function GenerateCode()

        Dim intRnd As Integer

        Dim intStep As Integer = Nothing

        Dim strname As String

        Dim intlength As Integer

        Dim strinputstring As String = ""

        Dim Numbers As String = "1234567890"

        Dim Lower As String = "abcdefghijklmnopqrstuvwxyzyz"

        Dim Upper As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZYZ"

        Dim intnamelength As Integer = 1



        If CheckBox1.Checked Then strinputstring &= Lower

        If CheckBox2.Checked Then strinputstring &= Numbers

        If CheckBox3.Checked Then strinputstring &= Upper





        intlength = Len(strinputstring)




        Integer.TryParse(NumericUpDown1.Text, intnamelength)


        Randomize()



        strname = ""



        For inStep = 1 To intnamelength



            intRnd = Int(Rnd() * intlength) + 1



            strname = strname & Mid(strinputstring, intRnd, 1)



        Next



        Return strname


    End Function

Fourth - Double Click Textbox1 insert this:

Now back to that label two thing look at the code and you can see it's text is going to change if the Password is strong enough xD:P

     If TextBox1.TextLength < 9 Then

            ProgressBar1.Value = 5


        End If


        If TextBox1.TextLength > 9 Then

            ProgressBar1.Value = 25

        End If

        If TextBox1.TextLength > 19 Then

            ProgressBar1.Value = 50

        End If

        If TextBox1.TextLength > 30 Then

            ProgressBar1.Value = 75

        End If

        If TextBox1.TextLength > 51 Then

            ProgressBar1.Value = 100

        End If

        If TextBox1.TextLength < 8 Then

            Label2.Text = "Poor!!"

            Label2.ForeColor = Color.White

            Label2.BackColor = Color.Red

            Me.BackColor = Color.Red

            MenuStrip1.BackColor = Color.Red

            CheckBox1.ForeColor = Color.White

            CheckBox2.ForeColor = Color.White

            CheckBox3.ForeColor = Color.White

            MenuStrip1.ForeColor = Color.White

            Label1.ForeColor = Color.White

        End If

        If TextBox1.TextLength > 8 Then

            Label2.Text = "Good"

            Label2.ForeColor = Color.White

            Label2.BackColor = Color.Green

            Me.BackColor = Color.Green

            MenuStrip1.BackColor = Color.Green

            CheckBox1.ForeColor = Color.White

            CheckBox2.ForeColor = Color.White

            CheckBox3.ForeColor = Color.White

            MenuStrip1.ForeColor = Color.White

            Label1.ForeColor = Color.White

        End If

        If ProgressBar1.Value > 20 Then

            Label2.Text = "Excellent"

            Label2.ForeColor = Color.White

            Label2.BackColor = Color.Green

        End If

        If ProgressBar1.Value > 50 Then

            Label2.Text = "Outstanding"

            Label2.ForeColor = Color.White

            Label2.BackColor = Color.Green

        End If

    End Sub

OK guys this is it if I missed anything I am sorry I am kinda tired lol 00:08 here I will be happy to help anyone who is stuck just reply here don't ask something to complicated I am still new myself lol (School Student).


Thanks for reading!

( YouTube - How to make password Generator ) <<<<

Edited by CriticalError, 27 July 2010 - 03:55 AM.


#2
Sky

Sky

    Learning Programmer

  • Members
  • PipPipPip
  • 83 posts
Nice tutorial!

#3
Jhost

Jhost

    Newbie

  • Members
  • PipPip
  • 11 posts
Nice tutorial, I learned a lot about Visual Basic and got a useful tool. Is there anyway to have it use a certain template like 3 letters 2 numbers 3 letters if selected i.e. SSS99SSS
Posted Image
Posted Image

#4
CriticalError

CriticalError

    Newbie

  • Members
  • PipPipPip
  • 42 posts
Nah sorry I don't know how to do that if I figure it out I will let you know.

#5
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,086 posts

Quote

Nice tutorial, I learned a lot about Visual Basic and got a useful tool. Is there anyway to have it use a certain template like 3 letters 2 numbers 3 letters if selected i.e. SSS99SSS
Instead of stepping trough intNameLength, you can loop trought the template, character by character.
for each character, check if it's numeric OR lowercase OR uppercase (switch or if else if else )

  • If it's numeric: strname = strname & Mid(Numbers, rand, 1)
  • if it's lowercase: strname = strname & Mid(Lower, rand, 1)
  • if it's uppercase: strname = strname & Mid(Upper, rand, 1)


#6
Demon

Demon

    Newbie

  • Members
  • PipPip
  • 18 posts
Great tut really enjoyed it :w00t: one thing you could have done though would be estimating hack times

 If TextBox1.TextLength < 8 Then

            Label2.Text = "50 seconds"


#7
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts

Demon said:

Great tut really enjoyed it :w00t: one thing you could have done though would be estimating hack times

 If TextBox1.TextLength < 8 Then
            Label2.Text = "50 seconds"

Yeah, it would be nice. For example a-z, A-Z and 0-9 if you used them all makes a complexity of 62^8, on a single modern processor that may take a very very long time though, like three months. It makes a HUGE difference to use complex passwords.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.