ASP & Active Directory

  • Thread starter Steven Marshall
  • Start date
S

Steven Marshall

I would like to check login credentials, ie username and password, from
Active Directory via an asp page. This will allow users to login to a
restricted area of the website using their windows login and password. I
read a thread about it on here, but it just said that it was possible, it
didn't say how it was possible. Any suggestions? Examples would be
EXCELLENT.
 
T

Tom Kaminski [MVP]

Steven Marshall said:
I would like to check login credentials, ie username and password, from
Active Directory via an asp page. This will allow users to login to a
restricted area of the website using their windows login and password. I
read a thread about it on here, but it just said that it was possible, it
didn't say how it was possible. Any suggestions? Examples would be
EXCELLENT.

here you go ...

<html>
<head>
</head>
<body>
<form action=authad.asp method=post>
Username: <input type=text name=strUserName><br>
Password: <input type=password name=strPassword><br>
<input type=submit name=btnSubmit>
</form>
<%
If Request.Form("strUsername") <> "" Then
Dim strADsPath
strADsPath = "WinNT://yourdomain"

'userid =
strUserName = "yourdomain\" & Request.Form("strUserName")
strPassword = Request.Form("strPassword")

if (not strADsPath= "") then 'if and ADS Object path has been provided
proceed with authentication

' bind to the ADSI object and authenticate Username and password
Dim oADsObject
Set oADsObject = GetObject(strADsPath)
response.write "Authenticating...<br><br>"
Dim strADsNamespace
Dim oADsNamespace
strADsNamespace = left(strADsPath, instr(strADsPath, ":"))
set oADsNamespace = GetObject(strADsNamespace)
Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, strUserName,
strPassword, 0)
' we're only bound if err.number = 0
if not (Err.number = 0) then
Response.Write "<font color='red'><font size = 5><u><b>Authentication has
failed...<b></u></font></font>"
'Response.Write "Failed to bind to object <b>" & strADsPath & "</b><br>"
'response.write err.description & "<p>"
'Response.write "Error number is " & err.number & "<br>"
Session("Auth") = "NO"
else
Response.Write "<font color='blue'>USER AUTHENTICATED!</font><br>"
'Response.Write "Currently viewing object at <b>" & oADsObject.ADsPath &
"</b><br>"
'Response.Write "Class is " & oADsObject.Class & "<br>"
Session("Auth") = "YES"
end if
'response.write "<p>"
end if
End If
%>
</body>
</html>
 
S

Steven Marshall

A@T said:
here you go ...

<html>
<head>
</head>
<body>
<form action=authad.asp method=post>
Username: <input type=text name=strUserName><br>
Password: <input type=password name=strPassword><br>
<input type=submit name=btnSubmit>
</form>
<%
If Request.Form("strUsername") <> "" Then
Dim strADsPath
strADsPath = "WinNT://yourdomain"

'userid =
strUserName = "yourdomain\" & Request.Form("strUserName")
strPassword = Request.Form("strPassword")

if (not strADsPath= "") then 'if and ADS Object path has been provided
proceed with authentication

' bind to the ADSI object and authenticate Username and password
Dim oADsObject
Set oADsObject = GetObject(strADsPath)
response.write "Authenticating...<br><br>"
Dim strADsNamespace
Dim oADsNamespace
strADsNamespace = left(strADsPath, instr(strADsPath, ":"))
set oADsNamespace = GetObject(strADsNamespace)
Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, strUserName,
strPassword, 0)
' we're only bound if err.number = 0
if not (Err.number = 0) then
Response.Write "<font color='red'><font size = 5><u><b>Authentication
has
failed...<b></u></font></font>"
'Response.Write "Failed to bind to object <b>" & strADsPath & "</b><br>"
'response.write err.description & "<p>"
'Response.write "Error number is " & err.number & "<br>"
Session("Auth") = "NO"
else
Response.Write "<font color='blue'>USER AUTHENTICATED!</font><br>"
'Response.Write "Currently viewing object at <b>" & oADsObject.ADsPath &
"</b><br>"
'Response.Write "Class is " & oADsObject.Class & "<br>"
Session("Auth") = "YES"
end if
'response.write "<p>"
end if
End If
%>
</body>
</html>
When I use a valid login it works and gives me the "USER AUTHENTICATED!",
however when I use an invalid login, I get:

Authenticating...

error '8007052e'

/authad.asp, line 42


Line 42 is "Set oADsObject = oADsNamespace.OpenDSObject(strADsPath,
strUserName, strPassword, 0)". All on one line.

Thanks for the help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,351
Latest member
RoxiePulli

Latest Threads

Top