VB login code used to validate User type, username +password

August 1, 2015 at 13:40:46
Specs: Windows 7
Hi, all? i am a programming student and i want to create a VB lo-gin code used to validate User type, Username and password using SQL 2008 connection, Here is what i have tried to design:
, thnk you.

Imports System.Data.SqlClient
Public Class FrmSystemAccess
Dim dbpath As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + "\KBUC_.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
Dim con As New SqlConnection(dbpath) ' connection

'// SIMPLE UNIVERSAL CLEAR CODE (FOR NEXT BUTTON) Private Sub FrmSystemAccess_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Private Sub BtnLogin_Click(sender As System.Object, e As System.EventArgs) Handles BtnLogin.Click
If CombUserType.Text = "" Then
MessageBox.Show("Please select user type", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
End If
If TxtUserName.Text = "" Then
MessageBox.Show("Please enter user name", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
End If
If TxtPassword.Text = "" Then
MessageBox.Show("Please enter password", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
End If
con = New OleDbConnection(cs)
cmd = New OleDbCommand("SELECT UserType,UserName,Password FROM SystemAccessRegistration WHERE UserType = '" & CombUserType.Text & "' AND UserName = '" & TxtUserName.Text & "' AND Password = '" & TxtPassword.Text & "'", con)
rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)

If rdr.Read() = True Then
Dim i As Integer
ProgressBar1.Visible = True
ProgressBar1.Maximum = 5000
ProgressBar1.Minimum = 0
ProgressBar1.Value = 4
ProgressBar1.[Step] = 1
For i = 0 To 5000
Dim frm As New frmMainMenu()
frm.lblUser.Text = TxtUserName.Text
MessageBox.Show("Login is Failed...Try again !", "Login Denied", MessageBoxButtons.OK, MessageBoxIcon.[Error])
End If
If con.State = ConnectionState.Open Then
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
End Try
End Sub

See More: VB login code used to validate User type, username +password

Report •

August 1, 2015 at 15:03:55
I'm not clear what question, if any, you are asking. Is there a problem with the code you have given? If so what? What do you expect to happen and what actually happens?

Report •

August 2, 2015 at 00:46:04
Dear ijack thnks for your prompt response. Unfortunately the code is not working. i have been trying to build it from scratch. However, i want users to be able to select a user type e.g. Admin, accounts, HRM, Security and Operations from a combo box, then enter a username and password to log-in into the system and access a menu form which i have already created for further actions. i have already created a table of system user access registration using SQL Server 2008 database with the following fields: EmployeeID, UserType,FirstName, LastName,Email,UserName and Password. using this info, i want only authenticated users to be able to login, thnks.

message edited by godfrey

Report •
Related Solutions

Ask Question