Hi there in this article I started learning how to create a login system using Microsoft Visual Basic NET and Microsoft Access as my database. The code will ask the user to give the username and password and then our program will check if the username and password is really existing in our database if it is true it will display the second windows and greet the user. If the username and password does not exist in the database it will not allow the user to enter in the system. The code is very easy to understand and use. I use Microsoft Visual Studio 2012 Ultimate Edition and Microsoft Access 2010 to write this sample login system. I hope you will find my work useful. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Sample Program Output
Program Listing
' Login System in Visual Basic NET
' Written By Mr. Jake R. Pomperada, MAED-IT
' Date: June 17, 2017 Saturday
' Tool : Microsoft Visual Studio Ultimate Edition 2012
' Country of Origin : Mandaluyong City, Metro Manila Philippines
Imports System.Data.OleDb
Public Class Form1
Dim provider As String
Dim dataFile As String
Dim FirstName As String
Dim LastName As String
Dim connString As String
Dim myConnection As OleDbConnection = New OleDbConnection
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = "
dataFile = "D:\login_vbnet\login.accdb"
connString = provider & dataFile
myConnection.ConnectionString = connString
myConnection.Open()
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [login] WHERE [username] = '" & TextBox1.Text & "' AND [password] = '" & TextBox2.Text & "'", myConnection)
Dim dr As OleDbDataReader = cmd.ExecuteReader
Dim userFound As Boolean = False
While dr.Read
userFound = True
FirstName = dr("firstname").ToString
LastName = dr("lastname").ToString
End While
If userFound = True Then
Form2.Show()
Form2.Label1.Text = "Welcome " & FirstName & " " & LastName
Else
MsgBox("Sorry,username or password not found ", MsgBoxStyle.OkOnly, "Invalid Login")
End If
myConnection.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End
End Sub
End Class
No comments:
Post a Comment