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

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

While objReader.Read
If CStr(objReader.GetValue(0)) <> "1" Then
Return False
Else
'objReader.Close()
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)
Else
lblMessage.Text = "Invalid Login!"
End If
End If
End Sub

Recommended Answers

All 2 Replies

Hey Dorothy, you would get a lot more sucess posting in the Web Development Forum, using the relevant sub-forum.

http://www.daniweb.com/techtalkforums/forum31.html

If a moderator/admin does not move this for you, I would suggest copying and pasting it to a new thread in the relevant section.

Regards, David

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)

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.