Password Generator in VB.NET

Password Generator in VB.NET

This tutorial will guide you to a step by step tutorial on how to create a password generator in VB.Net

Problem

Create a Windows Form Application program in Visual Basic.Net that will allow users generate randomized password.

Description

This tutorial will allow the user to generate strong random Alphanumeric passwords.

Before the tutorial the following are required to start:

  • Microsoft Visual Studio 2008 – Above

The tutorial starts here:

  1. Open Microsoft Visual Studio 2012
  2. Select a New Project on the File menu.
  3. Select Visual Basic, Windows Form Application then click OK.
  4. We need to design our form by the following controls:
  • 1 Label – label for the Password.
  • 1 Text box – text box for the Password Text Box.
  • 3 Command buttons – 1 button to generate the password, 1 button to hide the password, 1 button to show the password.
  1. We will also name our form controls in this way:
  • txtpassword is the name of the textbox for the Search text box.
  • cmdgenerate is the name of the button for the search button.
  • cmdshow is the name of the button for the browse button.
  • cmdhide is the name of the button for the insert button.
  1. This is how we design the form. (Feel free to layout your own)
Password Generator Form Design
Password Generator Form Design

Figure 1. Design of the Form

  1. Double click the Generate Button and paste the following code.

Code here

  Dim Letters As New List(Of Integer)
        'add ASCII codes for numbers
        For i As Integer = 48 To 57
            Letters.Add(i)
        Next
        'lowercase letters
        For i As Integer = 97 To 122
            Letters.Add(i)
        Next
        'uppercase letters
        For i As Integer = 65 To 90
            Letters.Add(i)
        Next
        'select 8 random integers from number of items in Letters
        'then convert those random integers to characters and
        'add each to a string and display in Textbox
        Dim Rnd As New Random
        Dim SB As New System.Text.StringBuilder
        Dim Temp As Integer
        For count As Integer = 0 To 16
            Temp = Rnd.Next(0, Letters.Count)
            SB.Append(Chr(Letters(Temp)))
            txtpassword.Text = SB.ToString
        Next

End Code

Code Explanation:

The code adds an ASCII codes for numbers, then it selects 8 random integers from number of letters then converted it to characters add each to a string and display it in a textbox.

­

  1. Double click the Show button and paste the following code.

Code here

        txtpassword.UseSystemPasswordChar = False
        cmdhide.Visible = True
        cmdshow.Visible = False

End Code

Code Explanation:

The code shows the password using System Password Character and also hides the show button.

  1. Double click the hide button and paste the following code.

Code here

        txtpassword.UseSystemPasswordChar = True
        cmdhide.Visible = False
        cmdshow.Visible = True

End Code

Code Explanation:

The code hides the password using System Password Character and also hides the hide button.

Password Generator in VB.Net Final Output
Password Generator in VB.Net Final Output

­­­

Conclusion:

Password must be kept confidential and as strong as possible to prevent malicious someone to gain access to your systems, email and any other important accounts. With this tutorial, you might be able to integrate this in your system in order to automatically generate strong password. The project and source code is available for download and you may modify it based on your preferences and requirements.

Author:

Name: Charlie Devera
Email Address: charliedevera000@gmail.com

Free Download Source code (Password Generator in VB.Net)

You may visit our facebook page for more information, inquiries and comments.

Hire our team to do the project.

, , ,

Post navigation