473,669 Members | 2,393 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8799
"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
Jul 22 '05 #2
A@T wrote:
"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>

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.O penDSObject(str ADsPath,
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
2898
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 successfully. then when i try to create a Web Application i get the error "project 'ABC' could not be opened because the microsoft
0
1246
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 that!). We'd like users to be able to update their own details if at all possible. Has anyone seen/written/got a piece of code that retrieves a single user from AD and allows a webform/ASP to update Active Directory?
2
15186
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 problems: I've run the following query to setup the linked server: sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'
0
1054
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
1356
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 security only (removed anonymous access) so all users must be domain authenticated. I use the webpage headers in use with security and logging functions (ie: Request.ServerVariables("AUTH_USER")). We also use Exchange 2000 as our email system....
3
5326
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 data to any consumer. This means the consumer may be a Java app or any app on any platform. Now, my knowledge of returning data to consumers who are not .Net applications or platforms is limited. I was told to make sure that SOAP
5
1637
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 created a MyApp_WebUser user in SQL Server. My connection string, which is stored in my web.config file, is <add key="DB:CSA" value="data source=MyServer;initial catalog=CSA;uid=MyApp_WebUser;pwd=12345678" />
0
1268
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 = oADsNamespace.OpenDSObject(strADsPath, strUserName, strPassword, 0) place an on error resume next
1
4052
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 role within Active directory. For example, Region1 has 4 sites, Region 2 has 3 sites and so forth. All the sites are held in a single database table.
5
2366
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 ADS_PROPERTY_APPEND, "wbempath, Array(Product & "|" and Key) Basically, a convenient place for me to store and manage CD installation keys.
0
8465
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8383
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8894
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8587
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8658
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7407
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6210
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.