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
Create a Windows Form Application program in Visual Basic.Net that will allow users generate randomized password.
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:
- Open Microsoft Visual Studio 2012
- Select a New Project on the File menu.
- Select Visual Basic, Windows Form Application then click OK.
- 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.
- 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.
- This is how we design the form. (Feel free to layout your own)
Figure 1. Design of the Form
- Double click the Generate Button and paste the following code.
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
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.
- Double click the Show button and paste the following code.
txtpassword.UseSystemPasswordChar = False cmdhide.Visible = True cmdshow.Visible = False
The code shows the password using System Password Character and also hides the show button.
- Double click the hide button and paste the following code.
txtpassword.UseSystemPasswordChar = True cmdhide.Visible = False cmdshow.Visible = True
The code hides the password using System Password Character and also hides the hide button.
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.
Name: Charlie Devera
Email Address: [email protected]
You may visit our facebook page for more information, inquiries and comments.
Hire our team to do the project.