"Steven Marshall" <sm****@gmail.c om> wrote in message
news:#R******** ******@TK2MSFTN GP09.phx.gbl...
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.a sp method=post>
Username: <input type=text name=strUserNam e><br>
Password: <input type=password name=strPasswor d><br>
<input type=submit name=btnSubmit>
</form>
<%
If Request.Form("s trUsername") <> "" Then
Dim strADsPath
strADsPath = "WinNT://yourdomain"
'userid =
strUserName = "yourdomain \" & Request.Form("s trUserName")
strPassword = Request.Form("s trPassword")
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(strAD sPath)
response.write "Authenticating ...<br><br>"
Dim strADsNamespace
Dim oADsNamespace
strADsNamespace = left(strADsPath , instr(strADsPat h, ":"))
set oADsNamespace = GetObject(strAD sNamespace)
Set oADsObject = oADsNamespace.O penDSObject(str ADsPath, strUserName,
strPassword, 0)
' we're only bound if err.number = 0
if not (Err.number = 0) then
Response.Write "<font color='red'><fo nt size = 5><u><b>Authent ication 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'>US ER AUTHENTICATED!</font><br>"
'Response.Write "Currently viewing object at <b>" & oADsObject.ADsP ath &
"</b><br>"
'Response.Write "Class is " & oADsObject.Clas s & "<br>"
Session("Auth") = "YES"
end if
'response.write "<p>"
end if
End If
%>
</body>
</html>
--
Tom Kaminski IIS MVP
http://www.microsoft.com/windowsserv...y/centers/iis/ http://mvp.support.microsoft.com/ http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS