Private Function SiteLevelCustomAuthenticationMethod(ByVal UserName
As String,
ByVal Password
As String)
As Boolean
Dim boolReturnValue
As Boolean =
False
Dim strConnection
As String =
"Data Source=sql.bjorn.se;Initial Catalog=db0544;Persist Security Info=True;User ID=du0457;Password=Khgfh5hgf"
Dim Connection As SqlConnection =
New SqlConnection(strConnection)
Dim strSQL As
String = "Select * From Main"
Dim command As SqlCommand =
New SqlCommand(strSQL, Connection)
Dim Dr As SqlDataReader
Connection.Open()
Dr = command.ExecuteReader
While Dr.Read
If ((UserName = Dr("user").ToString) _
And (Password = Dr("pwd").ToString))
Then
boolReturnValue = True
End If
Dr.Close()
Return boolReturnValue
End While
End Function
End Class
I hope I brought something back to the community this way.
Now a question again - one's down, there are many to go, I guess; Login is fixed but the other login-related controls must have similar code, won't they? What about the code for, say, a CreateUserWizard control? If you can point me in the right direction,
I'd be grateful. Otherwise, thanks for your kind help so far.
From Sweden with love,
Pettrer
Coding is a nine-to-five job: Nine PM to Five AM.
Marked as answer by Iori_Jay on Oct 24, 2006 03:47 AM
pettrer
Participant
970 Points
469 Posts
Re: sql server 2000 + login features
Oct 17, 2006 09:30 PM|LINK
Hi there,
Minutes ago, I actually could see that for myself, for the very first time!!![:D]
I simply used the code from here http://www.c-sharpcorner.com/UploadFile/sushmita_kumari/Logincontrol101312006002845AM/Logincontrol1.aspx?ArticleID=c33d0072-8f7c-4958-a7dc-ca1809737193 - which provides the code for a login control using a table of one's own. I made a VB version of it - here it is in case someone wants it (passwords etc altered of course):
This is the complete aspx file:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Login.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="Form1" runat="server">
<div>
<asp:Login ID="Login1" runat="server">
</asp:Login>
</div>
</form>
</body>
</html>
This is the complete codebehind file:
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
Dim Authenticated As Boolean = False
Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password)
e.Authenticated = Authenticated
If (Authenticated = True) Then
Response.Redirect("Home.aspx")
End If
End Sub
Private Function SiteLevelCustomAuthenticationMethod(ByVal UserName As String, ByVal Password As String) As Boolean
Dim boolReturnValue As Boolean = False
Dim strConnection As String = "Data Source=sql.bjorn.se;Initial Catalog=db0544;Persist Security Info=True;User ID=du0457;Password=Khgfh5hgf"
Dim Connection As SqlConnection = New SqlConnection(strConnection)
Dim strSQL As String = "Select * From Main"
Dim command As SqlCommand = New SqlCommand(strSQL, Connection)
Dim Dr As SqlDataReader
Connection.Open()
Dr = command.ExecuteReader
While Dr.Read
If ((UserName = Dr("user").ToString) _
And (Password = Dr("pwd").ToString)) Then
boolReturnValue = True
End If
Dr.Close()
Return boolReturnValue
End While
End Function
End Class
I hope I brought something back to the community this way.
Now a question again - one's down, there are many to go, I guess; Login is fixed but the other login-related controls must have similar code, won't they? What about the code for, say, a CreateUserWizard control? If you can point me in the right direction, I'd be grateful. Otherwise, thanks for your kind help so far.
From Sweden with love,
Pettrer