Password Generator

This password generator is based on the class created by Obviex. The generator can create a unique password that does not include ambiguous character. It can create alphanumeric and special character password. The password will always start with a letter. The best part here is that you can choose if you want to include a special character or numeric value by simply adding the pre-defined constant in the array. This can be done by using the following code:
  1. Dim charGroups As Char()() = New Char()() _
  2. { _
  3. PASSWORD_CHARS_NUMERIC.ToCharArray(), _
  4. PASSWORD_CHARS_LCASE.ToCharArray() _
  5. }
Other values are PASSWORD_CHARS_UCASE and PASSWORD_CHARS_SPECIAL. Here’s an example code that calls the RandomPassword class.
  1. Imports System.Data.OleDb
  2.  
  3. Public Class frmGenPass
  4. Dim cnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Data.mdb;"
  5.  
  6. Private Sub btnGenPass_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenPass.Click
  7. Dim I As Integer
  8. Dim strPass As String
  9. Dim strSQL As String
  10.  
  11. For I = 1 To 10
  12. strPass = RandomPassword.Generate(6, 6)
  13.  
  14. Try
  15. ListBox1.Items.Add(strPass)
  16.  
  17. strSQL = "INSERT INTO Users ([Password]) VALUES ('" & strPass & "')"
  18.  
  19. ExecNonQuery(strSQL)
  20. Catch ex As Exception
  21. Debug.Print(ex.Message)
  22. End Try
  23. Next
  24. End Sub
  25.  
  26. 'Execute Non Query
  27. Public Sub ExecNonQuery(ByVal strSQL As String)
  28. Dim conn As OleDbConnection
  29. conn = New OleDbConnection
  30.  
  31. Try
  32. With conn
  33. If .State = ConnectionState.Open Then .Close()
  34.  
  35. .ConnectionString = cnString
  36. .Open()
  37. End With
  38.  
  39. Dim cmd As OleDbCommand = New OleDbCommand(strSQL, conn)
  40.  
  41. cmd.ExecuteNonQuery()
  42.  
  43. Catch ex As OleDbException
  44. MsgBox(ex.ToString)
  45. Finally
  46. conn.Close()
  47. End Try
  48. End Sub
  49.  
  50. Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  51. End
  52. End Sub
  53. End Class
You may also download the complete project below.

Add new comment