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.
- Public Class Form1
- Dim Username = "username" 'enter your username
- Dim Password = "password" 'enter your password
- Dim UP As Integer
- Private Sub usernamepassword()
- UP = 0
- If TextBox1.Text = "username" Then
- UP = UP + 1
- Else
- UP = UP - 1
- End If
- If TextBox2.Text = "password" Then
- UP = UP + 1
- Else
- UP = UP - 1
- End If
- 'Now Check UP Value to see if the username and password work
- If UP = 2 Then
- MessageBox.Show("Welcome, the password and username worked!"
- )
- 'Show a form or something
- ElseIf UP = -2 Then
- MessageBox.Show("Wrong Username or Password")
- End If
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- 'check if text is entered
- If TextBox1.Text = "" And TextBox2.Text = "" = True Then
- MessageBox.Show("Please enter a username and password"
- )
- ElseIf TextBox1.Text = "" = True Then
- MessageBox.Show("Please enter a username")
- If TextBox2.Text = "" = True Then
- MessageBox.Show("Please enter a password")
- End If
- Else
- usernamepassword() 'Check system
- End If
- End Sub
- End Class
0 comments :
Post a Comment