Avatar of GaiaGia
Flag for United States of America asked on

Login Control UserName Only Accept the Initial Test Value of UserName and Password, Can't Test Any other set


I am a beginner of .Net Web Developer.

I programmed a simple Web app in VB.NET 2005 to let an user log in at first, and the UserName will be passed to the next page for displaying his or her relevant information .

the Login Control connects to a data table in SQL Server 2005 for log in authentication. I used UserID stored in the database as value of UserName text field of the Login control.

The problem is, during my many tests, only the very first UserID and password (the password is actually an user's last name) got successfully log in, no matter how many time to repeat to use this set of value. Except this set of value, the Login process was never succeed when using any other pairs of UserID and LastName, even I ensured to type in correct value in the text fields.

Your advise will be very appreciate!

Part of my code: -----------------------------------------------------------------

Private Function YourValidationFunction(ByVal UserName As String, ByVal Password As String) As Boolean

        Dim boolReturnValue As Boolean = False
        Dim strConnection As String = "Data Source=myServerName;Initial Catalog=myDatabaseName;Integrated Security=True;"
        Dim sqlconnection As New SqlClient.SqlConnection(strConnection)
        Dim SQLQuery As String = "SELECT distinct [UserId],[Last name] FROM myUserTable"
        Dim command As New SqlClient.SqlCommand(SQLQuery, sqlconnection)
        Dim Dr As SqlClient.SqlDataReader
        Dr = command.ExecuteReader()
        While Dr.Read()
            If (UserName = Dr("UserID").ToString()) And (Password = Dr("Last name").ToString()) Then
                boolReturnValue = True
            End If
            Return boolReturnValue
        End While
        Return boolReturnValue
    End Function
ASP.NETMicrosoft SQL Server 2005Visual Basic.NET

Avatar of undefined
Last Comment

8/22/2022 - Mon
Nasir Razzaq

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Thank you, CodeCruiser!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.