How to Create a Local Password Lock in Visual Basic

Introduction: Welcome to my tutorial on how to create a Local Password Lock in Visual Basic. The fact that it's local just means that the password is hardcoded in to the program and can not be changed without editing the source code of the program. Steps of Creation: Step 1: First we want to create a program with; textbox1 - contain password, label1 - to indicate to the user where to input the password, button1 - to check the password. Step 2: Next we want to create a couple of variables. We want to set the password in a String variable and also set whether the Capitals in textbox1 (input password) need to be correct or not.
  1. Dim password As String = "Yorkiebar"
  2. Dim capsMatter As Boolean = True
Step 3: Now on the button1 click action event we want to first check if the entered password is set to a string, if it is we want to check if the caps matter or not...
  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2.     If (Not TextBox1.Text = Nothing) Then
  3.         If (capsMatter) Then
  4.         Else
  5.         End If
  6.     End If
  7. End Sub
Step 4: Finally we just need to check the password appropriately and output the conclusion. If you wanted to redirect them to another form on login you would type the name of the new form followed by ".Show()".
  1. If (capsMatter) Then
  2.     If (TextBox1.Text = password) Then
  3.         MsgBox("Unlocked!")
  4.     Else : MsgBox("Incorrect Password!")
  5.     End If
  6. Else
  7.     If (TextBox1.Text.ToLower() = password.ToLower()) Then
  8.         MsgBox("Unlocked!")
  9.      Else : MsgBox("Incorrect Password!")
  10.     End If
  11. End If
Project Complete! Below is the full source code and download to the project files.
  1. Public Class Form1
  2.     Dim password As String = "Yorkiebar"
  3.     Dim capsMatter As Boolean = True
  4.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  5.         If (Not TextBox1.Text = Nothing) Then
  6.             If (capsMatter) Then
  7.                 If (TextBox1.Text = password) Then
  8.                     MsgBox("Unlocked!")
  9.                 Else : MsgBox("Incorrect Password!")
  10.                 End If
  11.             Else
  12.                 If (TextBox1.Text.ToLower() = password.ToLower()) Then
  13.                     MsgBox("Unlocked!")
  14.                 Else : MsgBox("Incorrect Password!")
  15.                 End If
  16.             End If
  17.         End If
  18.     End Sub
  19. End Class

Add new comment