First, let me say that this posting saved me purchasing some rope and a sturdy chair. [;)] Now, my issue. After copying and pasting the code and getting everything to work, I realized that just the first user in the SQL table is allowed to authenticate.
No other person can. Any thoughts?
I'm so glad I stopped you from investing in some rope! ;-) Sturdy chairs, however, are nice to have.
I have no idea why you get this problem, but let me fill you in on what I did. After say 30 more hours of working with the controls I gave up and created them myself, using winforms. It's actually really easy, as long as you just want login functionality -
please tell me if you want to know how it's done.
However, I'd still be grateful if anyone could come up with a workable solution so that we could actually USE the login/create user wizard etc controls, together with an existing db. Conceptually I think it would be a piece of cake, but I have no idea how
to do the actual programming for it.
This is great, but the sqldatareader doesn't go any further than the first row!!
Can you please tell me what I'm doing wrong:
Protected
Sub Login1_Authenticate(ByVal sender
As Object,
ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs)
Handles Login1.Authenticate
Dim Authenticated
As Boolean =
False
If Authenticated =
True Then
Session("Username") = Login1.UserName
Response.Redirect(
"YourPage.aspx")
End If
End Sub
Private Function SiteLevelCustomAuthenticationMethod(ByVal UserName
As String,
ByVal Password
As String)
As Boolean
Dim boolReturnValue
As Boolean =
False
' Insert code that implements a site-specific custom
' authentication method here.
' This example implementation always returns false.
Dim strConnection
As String =
"server=xxx;database=xxx;uid=sa;pwd=xxx;"
Dim Connection
As New SqlConnection(strConnection)
Dim strSQL
As String =
"Select * From Customer"
Dim command
As New SqlCommand(strSQL, Connection)Dim Dr
As SqlDataReader
Connection.Open()
Dr = command.ExecuteReader()
While Dr.Read()
If (UserName = Dr("Email").ToString())
And (Password = Dr("Password").ToString())
Then
I had the same problem running that code also, I found the problem though (at least I think).
the Dr.Close() and Return boolReturnValue should be outside the while.
If you think about it, it should make sense as the connection is either closed in the first iteration or a return value is returned automatically in the first iteration.
So try moving it out of the while loop and it should work.
Oh and also its missing the close for the sqlConnection, you might want to add that in also
jsouders
Member
2 Points
1 Post
Re: sql server 2000 + login features
Sep 09, 2007 08:41 PM|LINK
First, let me say that this posting saved me purchasing some rope and a sturdy chair. [;)] Now, my issue. After copying and pasting the code and getting everything to work, I realized that just the first user in the SQL table is allowed to authenticate. No other person can. Any thoughts?
pettrer
Participant
970 Points
469 Posts
Re: sql server 2000 + login features
Sep 10, 2007 08:42 AM|LINK
Hi there,
I'm so glad I stopped you from investing in some rope! ;-) Sturdy chairs, however, are nice to have.
I have no idea why you get this problem, but let me fill you in on what I did. After say 30 more hours of working with the controls I gave up and created them myself, using winforms. It's actually really easy, as long as you just want login functionality - please tell me if you want to know how it's done.
However, I'd still be grateful if anyone could come up with a workable solution so that we could actually USE the login/create user wizard etc controls, together with an existing db. Conceptually I think it would be a piece of cake, but I have no idea how to do the actual programming for it.
All the best,
Pettrer
djfuller
Member
2 Points
1 Post
Re: sql server 2000 + login features
Nov 14, 2007 10:17 AM|LINK
This is great, but the sqldatareader doesn't go any further than the first row!!
Can you please tell me what I'm doing wrong:
Protected
Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate Dim Authenticated As Boolean = FalseAuthenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password)
e.Authenticated = Authenticated
If Authenticated = True Then Session("Username") = Login1.UserNameResponse.Redirect(
"YourPage.aspx") End If End Sub Private Function SiteLevelCustomAuthenticationMethod(ByVal UserName As String, ByVal Password As String) As Boolean Dim boolReturnValue As Boolean = False ' Insert code that implements a site-specific custom ' authentication method here. ' This example implementation always returns false. Dim strConnection As String = "server=xxx;database=xxx;uid=sa;pwd=xxx;" Dim Connection As New SqlConnection(strConnection) Dim strSQL As String = "Select * From Customer" Dim command As New SqlCommand(strSQL, Connection)Dim Dr As SqlDataReaderConnection.Open()
Dr = command.ExecuteReader()
While Dr.Read() If (UserName = Dr("Email").ToString()) And (Password = Dr("Password").ToString()) ThenboolReturnValue =
True End IfDr.Close()
Return boolReturnValue End While End Functiondelleung
Member
2 Points
2 Posts
Re: sql server 2000 + login features
Dec 13, 2007 07:31 PM|LINK
Hi guys,
I had the same problem running that code also, I found the problem though (at least I think).
the Dr.Close() and Return boolReturnValue should be outside the while.
If you think about it, it should make sense as the connection is either closed in the first iteration or a return value is returned automatically in the first iteration.
So try moving it out of the while loop and it should work.
Oh and also its missing the close for the sqlConnection, you might want to add that in also
kpizzle01
Member
14 Points
2 Posts
Re: sql server 2000 + login features
Apr 23, 2008 02:30 PM|LINK
This is a good post, but I found a problem with the following..
The logic is incorrect, and it renders a syntax error..
It should be this:
While Dr.Read If ((UserName = Dr("username").ToString)) And ((Password = Dr("password").ToString)) ThenboolReturnValue =
True End Ifpettrer
Participant
970 Points
469 Posts
Re: sql server 2000 + login features
Apr 28, 2008 05:14 PM|LINK
Well spotted!
BTW - over 30,000 views now on this thread - must be some kind of record...
/Pettrer