Jump to content

asp.net 2.0 login page error


Guest thestig888

Recommended Posts

Guest thestig888

hi there I'm currently trying to set up a login page for a site using webmatrix which presents the following message upon successful login "welcome" and "unknown login" if the details are incorrectly entered, however when i run the page neither of the messages are appearing when the submit button is pressed.the sql appears to be correct with the table being called users, the code for the login page is below

Function login(ByVal username As String, ByVal password As String) As System.Data.DataSet        Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=..\datab\assignment2-cclocks1.mdb"        Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)        Dim queryString As String = "SELECT [users].[username], [users].[Password] FROM [users] WHERE (([users].[usern"& _            "ame] = @Username) AND ([users].[Password] = @Password))"        Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand        dbCommand.CommandText = queryString        dbCommand.Connection = dbConnection        Dim dbParam_username As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter        dbParam_username.ParameterName = "@Username"        dbParam_username.Value = username        dbParam_username.DbType = System.Data.DbType.[string]        dbCommand.Parameters.Add(dbParam_username)        Dim dbParam_password As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter        dbParam_password.ParameterName = "@Password"        dbParam_password.Value = password        dbParam_password.DbType = System.Data.DbType.[string]        dbCommand.Parameters.Add(dbParam_password)        Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter        dataAdapter.SelectCommand = dbCommand        Dim dataSet As System.Data.DataSet = New System.Data.DataSet        dataAdapter.Fill(dataSet)        Return dataSet        Dim hashMethod as string        hashMethod = "MD5"        Dim encryptPassword as string        encryptPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(loginpassword.Text, hashMethod)        Dim loginpwd As New System.Data.DataSet        loginpwd = login(loginusername.Text, encryptPassword)        If loginpwd.tables(0).Rows.Count <> 1 Then        loginresult.text = "Unknown login"        Else        loginresult.text = "hello"        End If        test.text="ERROR in data insert : "    End Function

thanks.

Link to comment
Share on other sites

I'll try my best to answer the problem.First correction :You use a function within a function. It is like a wheel. There is no ending. This is your code.

Function A(ByVal vA As String, ByVal vB As String) As String    Dim ReturnVal As String = Nothing        A("Data for vA","Data for vB")    Return ReturnValEnd Function

You make function A but you call function A in function A. You make function login and you call function login in function login. There is no ending. So when you execute the script it will be like this :Step 1 :Execute login function.Step 2 :Execute login function while the current login function is running.Step 3 :Execute login function within the login function while the login function is running withing a running login function.Step 4 :Step 3 + Step 2Step 5 :Step 4 + Step 2Step 6 :.......................Second Correction :Avoid use button to call a function. Use button to call a method sub. It is a little complicated to call a function with a button because you have to add event handler by using AddHandler method. If you using sub procedure, it is more simple.

Public Sub DoLogin() Handles ButtonId.Click            If Login(UserID.text,Password.text) = True Then                        LoginMsg.text = "Your ID is true"            Else                        LoginMsg.text = "Try again."            End IfEnd SubPrivate Function Login(ByVal fUserID As String, ByVal fPassword As String) As Boolean            Dim ReturnVal As Boolean = False            'Some code for login            Return ReturnValEnd Function

One more thing, this is .NET programing. You should transfer this post in .NET room so there will be more people can help you.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...