473,608 Members | 2,287 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 8787
"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
2892
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
1244
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
15184
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
1353
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
1633
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
1267
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
2365
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
8002
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
8496
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...
0
8475
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8148
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
8338
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
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4024
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1594
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1329
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.