views:

534

answers:

4

I'm creating a login form for vb.net using ms access 2003 as database. But it only checks for the username and bypasses the password. Meaning that if the username is correct and the password doesn't jive with the username, the user can still enter the system. Here is my code:

Try

            Dim NoAcc As String
            Dim NoAccmod2 As String
            Dim NoPas As String

            Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb;Jet OLEDB:Database Password=nrew123$%^;")
            Dim cmd As OleDbCommand = New OleDbCommand("Select * from admintable where AdminName= '" & TextBox4.Text & "' ", cn)


            cn.Open()

            rdr = cmd.ExecuteReader
            If rdr.HasRows Then
                rdr.Read()
                NoAcc = rdr("AdminName")
                NoPas = rdr("AdminPass")
                If (TextBox4.Text = NoAcc And TextBox3.Text = NoPas) Then NoAccmod2 = NoAcc

                adminview.Show()



                Me.Hide()
            Else
                MsgBox("Incorrect Username/Password")
                TextBox4.Clear()
                TextBox3.Clear()

            End If
        Catch
            MsgBox("Error logging in, please try again", MsgBoxStyle.Exclamation)
        End Try

How do I do it so that it checks both username and password?

A: 

You could have BOTH the uname and pword in the database and "WHERE" on both, if you get no record back, then you have your answer.

tobrien
A: 

Try using System.String.Compare(String str1,String str2, Boolean ) As Integer like:

If (System.String.Compare(TextBox4.Text, NoAcc, false) And System.String.Compare(TextBox3.Text, NoPas, false)) Then NoAccmod2 = NoAcc
Kangkan
+1  A: 

You are using a single line IF .. THEN :
If (TextBox4.Text = NoAcc And TextBox3.Text = NoPas) Then NoAccmod2 = NoAcc so the next line will always be executed:
adminview.Show()

you have to rearrange your IF .. THEN conditions

Klaus
A: 

i'm creating a login form for a school database.i'm asking for codes for the login form.my form has a textbox for username and password, it has labels for username and password ,it has command buttons for ok and cancel.the username and password are supposed to be derived from recordsets in various tables so as to open the correct database.

ebenezer
This is a question, not an answer. Post it as its own question. If it is related to this question, cite it in your own question.
David-W-Fenton