hi! we are having trouble in our program. every time we click login button it will proceed to the next form even if it doesn't have anything on it. can you please help us regarding this problem

Private Sub Command1_Click()
Adodc1.RecordSource = " select * from login where username = ' " + Text1.Text + "'"

On Error Resume Next
    If (Adodc1.Recordset.EOF = False) Then
        If (Text2.Text = Adodc1.Recordset.Fields("password")) Then
        
        MsgBox "log in success"
        Unload Me
        Form2.Show
        Else
        MsgBox "invalid password"
        Text1.Text = ""
        Text2.Text = ""
        Text1.SetFocus
        End If
    Else
        MsgBox "invalid username"
        Text1.Text = ""
        Text2.Text = ""
        Text1.SetFocus
        End If
End Sub

Recommended Answers

All 4 Replies

On Error Resume Next----is evil, especially in the context of log in screens.

"select count(*) from login where username = ' " & Text1.Text & " ' and password = '" & Text2.Text &"'"

if count returns 1 proceed further and go to the next screen else re-prompt for login credentials.

Leave the On Error resume next.. It could allow anyone break into your database..

if (rs.eof=false) then
    if (text1.text= rs.field["username"]) and (text2.text= rs.field["password"]) then
        msgbox "Logged in Succesfully"
        frm2.show
        unload me
    else
     msgbox "invalid"
     text1.text= ""
     text2.text= ""
  end if
end if

Again, everybody is missing the question....

your code of -

Private Sub Command1_Click()
Adodc1.RecordSource = " select * from login where username = ' " + Text1.Text + "'"

should have some error trapping in it, see if any value was given, if not exit, as in...

Private Sub Command1_Click()
Adodc1.RecordSource = " select * from login where username = ' " + Text1.Text + "'"

If Text1.Text = vbNullstring Then
MsgBox "Please enter a valid username"
Text1.SetFocus
Exit Sub
Else
'Rest of your code here.....
End Sub

If you only want to track the password to know if the user has inserted the password correctly then you have this code... Personally, i think its more easier to track only the password.

rs.open select * from login where password = ' " + Text2.Text + "'"
    if (rs.eof=false) then
        if (text2.text)=rs.fields("password") then
         msgbox "log in successfully"
          form2.show
        else
             msgbox "login failed"
        end if
end if
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.