Jump to content
Guest thestig888

asp.net 2.0 login page error

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.

Share this post


Link to post
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.

Edited by Fiq

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...