Hello Everybody.
Can somebody help pls. I'm fresh from school and my first task is to develop an e-commerce website.
I've been trying to do the login page. No matter what i do i get "Invalid Login". What am i doing wrong. :sad:
Here's the code i use

Function ValidateUser(ByVal strUserName As String, ByVal strPassword As String) As Boolean

'//Connect to db
Dim myConnection As SqlConnection = New SqlConnection("data source=sqlserver; initial catalog=SpiritDB; uid=WebAccess; password=pword2005; integrated security=")

Dim sqlQuery As String
sqlQuery = "Select name, password From userinfo Where name = @strUsername AND password = @strPassword;"

'//create cmd and pass the string to the cmd
Dim myCommand As New SqlCommand(sqlQuery, myConnection)
Dim objParam1, objParam2 As SqlParameter

objParam1 = myCommand.Parameters.Add("@strUsername", SqlDbType.Char)
objParam2 = myCommand.Parameters.Add("@strPassword", SqlDbType.Char)
objParam1.Direction = ParameterDirection.Input
objParam2.Direction = ParameterDirection.Input
objParam1.Value = txtUsername.Text
objParam2.Value = txtPassword.Text

If myConnection.State = ConnectionState.Closed Then
End If
Dim objReader As SqlDataReader
objReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)

While objReader.Read
If CStr(objReader.GetValue(0)) <> "1" Then
Return False
Return True
End If
End While
Catch ex As Exception
Response.Write("Error Connecting to database!")
End Try

End Function

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
If Page.IsValid Then
'Connect to db for user validation
If ValidateUser(txtUsername.Text, txtPassword.Text) = True Then
FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, False)
lblMessage.Text = "Invalid Login!"
End If
End If
End Sub

12 Years
Discussion Span
Last Post by Dani

I would move this but I have no clue what language it is. VB.NET perhaps? (If it's not, please don't laugh at me)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.