Login Form without Database in Visual Basic .Net


Create a program in visual basic .net that will let the user to enter a username and password then the program will check if the username and password combination matches to the criteria set by the program.

Note: the program is no need for a database.


We will create a login form that has no database, to do that we are going to use an if else statement and operator And.

And operator is the logical as well as bitwise AND operator. If both the operands are true, then condition becomes true. This operator does not perform short-circuiting, i.e., it evaluates both the expressions.

Let’s go to work

  1. Open you Microsoft Visual Studio 2010, 2012 or higher, or just your Microsoft Visual Basic .Net.
  2. Create a new project (select File and New Project).
  3. For visual studio user: (select Visual Basic then Windows Form Application)
  4. Here is the sample form layout or design. Feel free to design your form.


We need to add the following controls:

2 labels
2 textboxes
2 buttons
1 checkbox

  1. Double click the OK button and paste the code below.
If TextBox1.Text = "" Then
MessageBox.Show("Please enter username")
Exit Sub
ElseIf TextBox2.Text = "" Then
MessageBox.Show("Please enter password")
Exit Sub
End If
If TextBox1.Text = "admin" And TextBox2.Text = "admin" Then
MessageBox.Show("welcome admin")
MessageBox.Show("incorrect username or password")
End If

Code Explanation:

The program will first validate the input of the user, the user must enter a username and password or else a message will appear that will notify the user that username and password field is required.

The program will then match or compare the user input to the criteria of the program. The username must be admin and password must also be admin which means that the username and password combination must be admin or else a message will prompt you that your username and password is incorrect.

  1. To clear the username and password field, kindly double click the Reset button and paste the code below.
  1. Additional feature of this program is to allow the user to view or to make its password visible or in simplest explanation is to view what you are typing in the password field. Kindly double click the Show password checkbox and paste the line of codes below.
If CheckBox1.Checked = True Then
TextBox2.PasswordChar = ""
TextBox2.PasswordChar = "*"
End If

Code Explanation:

If the user checks the checkbox, the user can view the characters being entered in the textbox, if the value of checkbox is unchecked then the user can only see asterisk symbol (*).

  1. Save and Run the project




, , ,

Post navigation