Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub btnGenerate_Click(sender As Object, e As EventArgs) Handles btnGenerate.Click
- ' First we must check that the number in
- ' txtLength.Text property is a real integer number or not
- If Not IsNumeric(txtLength.Text) Then
- MessageBox.Show("Password length must be a whole nmber")
- txtLength.Focus()
- Exit Sub
- End If
- ' It was an integer so we can keep on
- ' now we check that the pass length is not below 6
- ' because we want the password to be minimum 6 char long
- If CInt(txtLength.Text) < 6 Then
- MessageBox.Show("Password length must be 6 or higher")
- txtLength.Focus()
- Exit Sub
- End If
- ' okay, so the length is now a number and is 6 or more char lonng
- ' so we can begin the password generation
- ' setup som variables.
- Dim RandomClass As New Random()
- Dim UsableChars() As String = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
- Dim SpecialChars() As String = {"=", "+", "-", "_", "(", ")", "*", "&", "^", "%", "$", "#", "@", "!", "~", "`", "{", "}", "[", "]", ":", "'", "?", "/", ">", ".", ",", "<"}
- Dim FinalPassword As String = ""
- Dim index As Integer = 0
- Dim PassLength = CInt(txtLength.Text)
- Dim i As Integer
- For i = 1 To PassLength
- index = RandomClass.Next(0, UsableChars.Length() - 1)
- FinalPassword += UsableChars(index)
- Next
- txtPassword.Text = FinalPassword
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement