Simple Login Tutorial - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This tutorial will show you how to make a login program. This is a simple login program, after understanding how it works, you can try using a login program using a database

Open Visual Basic 2008 / 2010 / 2013 Express Edition. (If you don't have the program click here to download it for free.)

Click on Project next to Create:

Click on Windows Form Application, and name the project "Your Application" and then click Ok.

You can change the form text to "your application". Click on the form and then go to properties window, then change the text property.

You need to add another form to your application. To do that, click on Project on the menu bar, then click on Add Windows Form.:

A new window will appear. Click on Add:

Add a new Label and change it's text to whatever you like:

Go back to Form1:

Add a label and a textbox to the form. Change the label's text to "Username":

Add another label and a textbox to the form. Change the label's text to "Password":

We need the change the password text property. Right click on the textbox that will hold the password, click on properties, go to the properties window. Change the PasswordChar property to * :

Add a button to the form and change it's text to "Login"

Suppose we want the username = rfb and the password = reflection

Add the following button click event code

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "rfb" And TextBox2.Text = "reflection" Then
            Form2.Show()
        Else
            MsgBox("Sorry, username or password not found", MsgBoxStyle.OkOnly, "Invalid")
        End If
    End Sub

You can change the username and the password in the code where it says "rfb" for the username and "reflection" for the password.

Run the program and it should work fine.

If you enter a wrong username or a wrong password, you should get the following message:

If you enter the right username and the right password, the second form will appear:

Now that you learned the idea of how login works, you can use the a database to save usernames and passwords and check if the user supplied the right credentials in the next tutorial.


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.