A Revolution
From the Norm,
Towards Greatness
Home » » Visual Basic: How to create a Username & Password (Basic Security)

Visual Basic: How to create a Username & Password (Basic Security)

Written By Unknown on Tuesday, May 17, 2016 | 5:37 PM

Visual Basic: How to create a Username & Password (Basic Security)




Are you ready to learn how to create a basic security system for your Visual Basic project? Today's tutorial is going to go over a basic system that requires a person to enter a Username and Password, before they can access the main interface / premium pages on your App.

Before we get started, you are going to need to add the following to your Form.

  • Textbox1
  • Textbox2
  • Button1

Bellow is how I set up my form.





















Bellow is the 'bonus' code / script for this tutorial
  1. Public Class Form1
  2.     Dim Username = "username" 'enter your username
  3.     Dim Password = "password" 'enter your password
  4.     Dim UP As Integer
  5.     Private Sub usernamepassword()
  6.         UP = 0
  7.         If TextBox1.Text = "username" Then
  8.             UP = UP + 1
  9.         Else
  10.             UP = UP - 1
  11.         End If
  12.         If TextBox2.Text = "password" Then
  13.             UP = UP + 1
  14.         Else
  15.             UP = UP - 1
  16.         End If
  17.         'Now Check UP Value to see if the username and password work
  18.         If UP = 2 Then
  19.             MessageBox.Show("Welcome, the password and username worked!"
  20.                             )
  21.             'Show a form or something
  22.         ElseIf UP = -2 Then
  23.             MessageBox.Show("Wrong Username or Password")
  24.         End If
  25.     End Sub
  26.    
  27.     Private Sub Button1_Click(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles Button1.Click
  28.         'check if text is entered
  29.         If TextBox1.Text = "" And TextBox2.Text = "" = True Then
  30.             MessageBox.Show("Please enter a username and password"
  31.                             )
  32.         ElseIf TextBox1.Text = "" = True Then
  33.             MessageBox.Show("Please enter a username")
  34.             If TextBox2.Text = "" = True Then
  35.                 MessageBox.Show("Please enter a password")
  36.             End If
  37.         Else
  38.             usernamepassword() 'Check system
  39.         End If
  40.     End Sub
  41.    
  42. End Class
SHARE

About Unknown

0 comments :

Post a Comment