hello everybody,
i am have login form which is use to verify user name & password from
sql database
below is my code for login button nut the problem is it is not
verifying my password from database and simply giveing me msg
invalid password. please help me to overcome this problem
Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
Dim cnsql As SqlConnection
Dim cmsql As New SqlCommand()
Dim strsql As String
Dim dr As SqlDataReader
cnsql = New SqlConnection(connection)
g_login = Me.txtuser.Text
strsql = "select * from info_users where user_id = '" & g_login & "'"
cmsql = New SqlCommand(strsql, cnsql)
Dim valid As Boolean = False
Dim hasrows As Boolean = False
Dim strpassword As String = Me.txtpassword.Text
If g_login = "" Then
MessageBox.Show(" Cannot Be Blank ! ", "Login Form")
Me.txtuser.Focus()
Return
End If
Try
cnsql.Open()
dr = cmsql.ExecuteReader
If dr.HasRows Then
While dr.Read()
If strpassword = dr.Item("password") Then
valid = True
End If
End While
hasrows = True
dr.Close()
End If
Catch exo As SqlException
MsgBox(exo.Message)
Catch ex As Exception
MsgBox(ex.Message)
Finally
If cnsql.State = ConnectionState.Open Then
cnsql.Close()
End If
cmsql = Nothing
dr = Nothing
cnsql.Dispose()
GC.Collect()
End Try
icount = icount + 1
If valid = True Then
Me.Hide()
ITEMS.Show()
ElseIf icount = 3 Then
MsgBox(" Contact Your System Administrator ")
Me.txtuser.Focus()
Me.txtuser.Text = ""
Me.Close()
Else
MsgBox("Invalid Password")
Me.txtpassword.Focus()
Me.txtpassword.Text = ""
End If
End Sub
pls help me, by sending correct code to my Email Add :
[email protected]
thank's in advance