Home All Groups Group Topic Archive Search About


Author
2 Mar 2005 3:56 PM
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.
--
--
Steven Marshall
Web Technician

Author
2 Mar 2005 4:51 PM
Tom Kaminski [MVP]
"Steven Marshall" <smr***@gmail.com> wrote in message
news:#RNgBB0HFHA.1476@TK2MSFTNGP09.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.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>


Author
2 Mar 2005 5:28 PM
Steven Marshall
A@T wrote:

Show quote
> "Steven Marshall" <smr***@gmail.com> wrote in message
> news:#RNgBB0HFHA.1476@TK2MSFTNGP09.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.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!
--
--
Steven Marshall
Web Technician

AddThis Social Bookmark Button