Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Active Directory Authentication in ASP

Thread Tools

Active Directory Authentication in ASP

Michael B. Murdock
Posts: n/a
I have been attempting to find a script that works in a variety of AD
implementations to authenticate a user from a form in ASP. After many failed
attempts I developed the following test script that seems to work in a
majority of environments I have tested it in.

I am posting it for the benefit of other developers trying to solve the same

Best regards,

Mike Murdock
Web Content Management Solutions
mmurdock (at) starphire (d0t) com


I have updated the script to make it more generic and work in multiple
domain environments and am posting it here as a resource for other users.

Mike Murdock
Web Content Management Solutions
mmurdock (at) starphire (d0t) com

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<title>LDAP Authentication Test</title>


dim submit
dim UserName
dim Password

UserName = "domain\JohnDoe"
Password = ""
Domain = ""

submit = request.form("submit")

if submit = "Authenticate" then
UserName = request.form("UserName")
Password = request.form("Password")
Domain = request.form("Domain")
result = AuthenticateUser(UserName, Password, Domain)
if result then
response.write "<h3>Authentication Succeeded!</h3>"
response.write "<h3>Authentication Failed!</h3>"
end if
end if

response.write "<hr><form method=post>"
response.write "<table>"
response.write "<tr>"
response.write "<td><b>Username:&nbsp;</b></td><td><input type=""text""
name=""UserName"" value=""" & UserName & """ size=""30""><br><small>Enter as
""DOMAIN\UserName"" or ""(E-Mail Removed)"" or ""\UserName"" in a
single domain environment</small></td>"
response.write "</tr>"
response.write "<tr>"
response.write "<td><b>Password:&nbsp;</b></td><td><input
type=""password"" name=""Password"" value=""" & Password & """
response.write "</tr>"
response.write "<tr>"
response.write "<td><b>AD Domain:&nbsp;</b></td><td><input type=""text""
name=""Domain"" value=""" & Domain & """ size=""30""><br><small>Enter the AD
Server FQDN, IP Address, or DN<br>Examples: """" or
"""" or
response.write "</tr>"
response.write "<tr>"
response.write "<td>&nbsp;</td><td><input name=""submit""
type=""submit"" value=""Authenticate""></td>"
response.write "</tr>"
response.write "</table>"
response.write "</form>"

function AuthenticateUser(UserName, Password, Domain)
dim strUser
' assume failure
AuthenticateUser = false

strUser = UserName
strPassword = Password

strQuery = "SELECT cn FROM 'LDAP://" & Domain & "' WHERE objectClass='*' "
set oConn = server.CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOOBJECT"
oConn.Properties("User ID") = strUser
oConn.Properties("Password") = strPassword
oConn.Properties("Encrypt Password") = true "DS Query", strUser, strPassword

set cmd = server.CreateObject("ADODB.Command")
set cmd.ActiveConnection = oConn
cmd.CommandText = strQuery
on error resume next
set oRS = cmd.Execute
if oRS.bof or oRS.eof then
AuthenticateUser = false
AuthenticateUser = true
end if
set oRS = nothing
set oConn = nothing

end function



Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET 2.0 Active Directory authentication questions ASP .Net 0 05-18-2006 03:52 PM
ASP.NET 1.1 Application Pool Identity and user authentication problem with AD (Active Directory) ASP .Net 4 12-05-2005 04:08 PM
Active Directory authentication issue with ASP.NET & IIS susurla ASP .Net 1 08-26-2005 04:54 PM
Asp.Net Forms authentication using Active Directory =?Utf-8?B?RWdiZXJ0?= ASP .Net 0 11-03-2004 11:49 AM
Windows Authentication with and against Active Directory Patrick ASP .Net Security 1 09-02-2004 08:25 AM