473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

ASP & Active Directory

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
Jul 22 '05 #1
2 8763
"Steven Marshall" <sm****@gmail.com> wrote in message
news:#R**************@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>
--
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
Jul 22 '05 #2
A@T wrote:
"Steven Marshall" <sm****@gmail.com> wrote in message
news:#R**************@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
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vamsi | last post by:
Hi Guys, I have installed Visual Studio.Net on my windows XP machine. First after installing all the required WCU, then installed the Visual Studio.Net. All set up was completed...
0
by: Enigma Webmaster | last post by:
Hi All, We have written a set of functions to retrieve the current userlist from Active Directory and it works just fine. (We did have a few problems with the Address field, but we've cheated...
2
by: James Allan | last post by:
Hello -- I'm trying to get SQL Server 2000 on a Windows 2000 Server to be able to query an Active Directory. We've got two domain servers one Win2000 and one Win2003. However, I'm having...
0
by: Shri | last post by:
hi i am new to active directory and stuff can some one please help me in finding all "sites" and "subnets" from active directory using C#.net thanks in advance red
1
by: Jim in Arizona | last post by:
I've built a small IT helpdesk ticket system using the .NET 2.0 Beta 2 framework w/VS 2005 Beta 2. This system sits on an IIS 5.0 server, fully patched. The IIS server is set for windows inegrated...
3
by: Demetri | last post by:
Hello, My company has charged me with creating a web service that will validate a user and return the user's roles via Active Directory. The requirement is that the web service must return...
5
by: Terry Holland | last post by:
I have an intranet application that comprises an ASP.Net application connecting to a SQL Server DB The application has 150 users. At the moment I am connecting using the following setup I have...
0
by: mduff | last post by:
This is actually a great script that will help authenticate your username and password within your domain. One thing I would correct is directly above the line that indicates: Set oADsObject =...
1
by: Tim | last post by:
Folks, I have 3 loosely linked problems which I am would appreciate feedback on. 1). T-Sql and Active directory roles. We want to be able to control access to data within a table based on a...
5
by: Mark B | last post by:
Hi experts, I'm converting a homebrew AD management progam I wrote, from VB6 to VB 2008. I've got some code that sticks values in to Active Directory like this:- objOU.PutEx...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.