A simple program that I wrote that show you how to create login security using Visual Basic NET and MySQL as our database.
I hope you will find my work useful. Thank you.
I am currently accepting programming work, it projects, school and application development.
programming projects, thesis and capstone projects, IT consulting.
work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.
My personal website is http://www.jakerpomperada.com
My personal website is http://www.jakerpomperada.com
Sample Program Output
Program Listing
Imports MySql.Data.MySqlClient
Public Class Form1
Dim cmd As New MySqlCommand
Dim da As New MySqlDataAdapter
Dim con As MySqlConnection = conn()
Public Function conn() As MySqlConnection
Return New MySqlConnection("server=localhost;user id=root;password=;database=studentdb")
End Function
Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
Dim sql As String
Dim publictable As New DataTable
Try
If txtuname.Text = "" And txtpass.Text = "" Then
MsgBox("Password or Username Textbox Cannot be Empty.", vbCritical, "Remainder")
txtuname.Text = ""
txtpass.Text = ""
txtuname.Focus()
Else
sql = "select * from tbluseraccounts where username ='" & txtuname.Text & "' and userpassword = '" & txtpass.Text & "'"
With cmd
.Connection = con
.CommandText = sql
End With
da.SelectCommand = cmd
da.Fill(publictable)
If publictable.Rows.Count > 0 Then
Dim user_type, name As String
user_type = publictable.Rows(0).Item(4)
name = publictable.Rows(0).Item(2)
If user_type = "Admin" Then
MsgBox("Welcome " & name & " you login as Administrator ", vbInformation, "Welcome")
lbllogin.Text = "Logout"
GroupBox1.Enabled = False
txtuname.Text = ""
txtpass.Text = ""
lblname.Font = New Font(lblname.Font, FontStyle.Bold)
lblname.Text = "Hi, " & UCase(name)
ElseIf user_type = "Encoder" Then
MsgBox("Welcome " & name & " you login as Encoder ", vbInformation, "Welcome")
lbllogin.Text = "Logout"
GroupBox1.Enabled = False
txtuname.Text = ""
txtpass.Text = ""
lblname.Font = New Font(lblname.Font, FontStyle.Bold)
lblname.Text = "Hi, " & UCase(name)
Else
MsgBox("You login as Guest!", vbInformation, "Welcome")
lbllogin.Text = "Logout"
GroupBox1.Enabled = False
txtuname.Text = ""
txtpass.Text = ""
lblname.Font = New Font(lblname.Font, FontStyle.Bold)
lblname.Text = "Hi, " & UCase(name)
End If
Else
MessageBox.Show("Username or Password is Incorrect" & vbNewLine _
& vbNewLine _
& "Kindly try again please." & vbNewLine & vbNewLine _
& "Program developed By : Mr. Jake Rodriguez Pomperada" & vbNewLine _
, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtuname.Text = ""
txtpass.Text = ""
txtuname.Focus()
End If
da.Dispose()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
con.Clone()
End Sub
Private Sub lbllogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbllogin.Click
If lbllogin.Text = "Logout" Then
lbllogin.Text = "Login"
lblname.Text = "Hi, Guest!"
ElseIf lbllogin.Text = "Login" Then
GroupBox1.Enabled = True
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GroupBox1.Enabled = False
Dim toolTip1 As New ToolTip()
toolTip1.ShowAlways = True
toolTip1.SetToolTip(lbllogin, "Click here to login or logout to the system.")
End Sub
End Class
studentdb.sql
-- phpMyAdmin SQL Dump
-- version 4.8.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jan 18, 2019 at 09:11 AM
-- Server version: 10.1.37-MariaDB
-- PHP Version: 7.3.0
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `studentdb`
--
-- --------------------------------------------------------
--
-- Table structure for table `tbluseraccounts`
--
CREATE TABLE `tbluseraccounts` (
`userID` int(11) NOT NULL,
`username` varchar(255) DEFAULT NULL,
`users_name` varchar(255) DEFAULT NULL,
`userpassword` varchar(255) DEFAULT NULL,
`usertype` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Dumping data for table `tbluseraccounts`
--
INSERT INTO `tbluseraccounts` (`userID`, `username`, `users_name`, `userpassword`, `usertype`) VALUES
(1, 'admin', 'Jake R. Pomperada', 'admin', 'Admin'),
(2, 'jacob', 'Jacob Samue F. Pomperada', 'jacob', 'guest'),
(3, 'iya', 'Julianna Rae F. Pomperada', 'iya', 'Encoder');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `tbluseraccounts`
--
ALTER TABLE `tbluseraccounts`
ADD PRIMARY KEY (`userID`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `tbluseraccounts`
--
ALTER TABLE `tbluseraccounts`
MODIFY `userID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;