Jump to content

Generate A Simple Password

- - - - -

  • Please log in to reply
2 replies to this topic

#1
HighKing Scott

HighKing Scott

    Newbie

  • Members
  • PipPip
  • 15 posts
Generating a Simple random Character string and having the ability to set the length of the password.
Here is what my form looks like:
Posted Image

Open the code view of your form and then create a function called "GenerateRandomString"

    Function GenerateRandomString(ByRef length As Integer) As String

        Randomize()


        Dim allowableChars As String

        allowableChars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()"


        Dim i As Integer

        For i = 1 To length

            GenerateRandomString = GenerateRandomString & Mid$(allowableChars, Int(Rnd() * Len(allowableChars) + 1), 1)

        Next

    End Function


You can set the allowableChars to anything you want. for instance if you did not want special chars (!@#$% etc...) then you can just remove those from the allowable chars.

Finally on your button click event:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim sLgth As String = TextBox2.Text


        If TextBox2.Text = "" Then

            MsgBox("Please enter a Char. Length")

        Else

            TextBox1.Text = GenerateRandomString(CInt(sLgth))

        End If

    End Sub




#2
Java_

Java_

    Newbie

  • Members
  • PipPip
  • 13 posts
Thanks for this. :D

#3
stevie754

stevie754

    Programmer

  • Members
  • PipPipPipPip
  • 110 posts
Thanks :) helpful post will use this in the future




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users