hi guys,ive been working on trying to create a login form.
ms Access side:
-used a logininfo.mdb database with columns :username,password,job
vb 2008 side:
-login form with clerk rad button,manager rad button,username text box,password textbox and login button
now the challenge im having is that only the "Clerk" can login properly,ive used the same code for "Manager"
but just swapped the variables.however "manager" cant login
pls pls pls help asap,gotta submit this system soon
Imports System.Data.OleDb
Public Class database
Public Sub login()
Dim con As New OleDb.OleDbConnection
con.ConnectionString = "PROVIDER=Microsoft.JET.OLEDB.4.0;Data Source = ..logininfo.mdb"
Dim cmd As OleDbCommand = New OleDbCommand("SELECT job,username,password FROM login where username=? and password=?", con)
cmd.Parameters.AddWithValue("username", Form1.TextBox1.Text)
cmd.Parameters.AddWithValue("password", Form1.TextBox2.Text)
Try
con.Open()
Dim read As OleDbDataReader = cmd.ExecuteReader()
If read.HasRows Then
read.Read()
''validate clerk
If Form1.TextBox1.Text.ToLower() = read.Item("username").ToString And Form1.TextBox2.Text.ToLower = read.Item("password").ToString And Form1.rdbclerk.Checked Then
MsgBox("Login successful")
frmclk.ShowDialog()
Form1.Hide()
Else
If String.IsNullOrEmpty(Form1.TextBox1.Text) Xor String.IsNullOrEmpty(Form1.TextBox2.Text) Xor Form1.rdbclerk.Checked = False _
Xor Form1.rdbmgr.Checked Then
MsgBox("emp Login unsuccessful,pls type the correct details and select the correct usertype")
End If
End If
'validate manager
If Form1.TextBox1.Text.ToLower() = read.Item("username").ToString And Form1.TextBox2.Text.ToLower = read.Item("password").ToString And Form1.rdbmgr.Checked Then
MsgBox("Login successful")
frmclk.ShowDialog()
Form1.Hide()
Else
If String.IsNullOrEmpty(Form1.TextBox1.Text) Xor String.IsNullOrEmpty(Form1.TextBox2.Text) Xor Form1.rdbclerk.Checked = False _
Xor Form1.rdbclerk.Checked Then
MsgBox("emp Login unsuccessful,pls type the correct details and select the correct usertype")
End If
End If
Else
MsgBox("Login unsuccessful,no connection")
End If
read.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
con.Close()
End Try
End Sub
End Class[/pre]
Software/Hardware used:
vb.net 2008
ASKED:
March 22, 2012 10:27 AM
UPDATED:
March 23, 2012 2:16 PM
Looks to me like your READ is only reading the first record. When you compare the clerk’s login info against it, it is OK, but when you compare the manager’s login info against the first record from the database, it fails. I think you need a way to loop through the records of the password database.
“Looks to me like your READ is only reading the first record.”
I don’t think it needs to read more than 1 record, since only one user will be being validated on each try.
I think part of the problem is here:
Else
If String.IsNullOrEmpty(Form1.TextBox1.Text) Xor String.IsNullOrEmpty(Form1.TextBox2.Text) Xor Form1.rdbclerk.Checked = False _
Xor Form1.rdbmgr.Checked Then
MsgBox(“emp Login unsuccessful,pls type the correct details and select the correct usertype”)
End If
End If
Because of this code, if rdbmgr is checked, an unsuccessful login message will be displayed, no matter what the user entered as username and password.
But, it seems that it should then continue to validate using the manager validation code, and display a login successful message if the provided credentials were correct.
Dissector, can you tell us what happens when you try to login as a manager ?
Oops, Carlosdl is correct. I didn’t follow the logic. The way the IFs are set up the program flow doesn’t have a chance to get to the manager vaildation.