473,508 Members | 4,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP page to authenticate username and password with active directory

Hello,

I'm trying to create an ASP page where users can type in a username
and password, and these credential should be checked with active
directory. If username and password are correct, the script will
continue to run otherwise it will stop. Below you will find my code
I've programmed until now, at this moment I've got one big problem:
my script stops at the line:
Set oRootDSE = GetObject("LDAP://RootDSE")
Why is this GetObject thing giving so much problems and is there a
way to let it work? Maybe there are already scripts available to do
the same thing, anyway, all help is welcome. Here comes the code:

<html>

<head>
<meta http-equiv="Content-Language" content="nl-be">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>username</title>
</head>

<body>
<SCRIPT LANGUAGE=VBScript>

<!--

Option Explicit

Dim bValid
Dim oRootDSE
Dim oDSObj
Dim oAuth
Dim szNamingContext
Const ADS_SECURE_AUTHENTICATION=1
Dim szUserId, szPasswd
Sub B1_OnClick

bValid = True

Call CheckField(document.form1.username.Value, "Please enter a
value in the field.")
Call CheckField(document.form1.password.Value, "Please enter a
value in the field.")
If bValid Then

szUserId = document.form1.username.value
szPasswd = document.form1.password.value
' Retrieve the current domain
Set oRootDSE = GetObject("LDAP://RootDSE")

szNamingContext = oRootDSE.Get("defaultNamingContext")
' Validate against the namespace
Set oDSObj = GetObject("LDAP:")
Set oAuth = oDSObj.OpenDSObject("LDAP://" & szNamingContext, _
szUserId, szPasswd, ADS_SECURE_AUTHENTICATION)

' User authenticated if we get here
bAuthenticateUser = True
End If

End Sub

Sub CheckField(ByVal strFieldValue, ByVal strMessage)

If strFieldValue = "" Then

MsgBox strMessage, 0

bValid = False

End If

End Sub

-->

</Script>

<FORM NAME="form1">
<p>&nbsp;</p>
<p align="center">username: <input type="text" name="username"
size="20"></p>
<p align="center">password: <input type="password" name="password"
size="20"></p>
<p>&nbsp;</p>
<p align="center">&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ; <input
type="submit" value="Submit"
name="B1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;

<input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>

Jul 19 '05 #1
5 12093
"Joeri KUMBRUCK" <Jo************@dhl.com> wrote in message
news:41***************@dhl.com...
Hello,

I'm trying to create an ASP page where users can type in a username
and password, and these credential should be checked with active
directory.


Here's the one I use:

authad.asp
<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"

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.iisfaq.com/
http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS
http://www.tryiis.com
Jul 19 '05 #2
Hello Tom,

thanks for your help! I've copy/pasted your code, but it doesn't work. I
can't see anything wrong in it, except some variables which are not
defined. Do I need to do anything special to let it work? I can fill in
the fields and press submit, but there is no result showing...

thanks for your help,

Joeri

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #3
"Joeri Kumbruck" <jo************@dhl.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Hello Tom,

thanks for your help! I've copy/pasted your code, but it doesn't work. I
can't see anything wrong in it, except some variables which are not
defined. Do I need to do anything special to let it work? I can fill in
the fields and press submit, but there is no result showing...


Nothing at all shows? Does any ASP work?

--
Tom Kaminski IIS MVP
http://www.microsoft.com/windowsserv...y/centers/iis/
http://mvp.support.microsoft.com/
http://www.iisfaq.com/
http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS
http://www.tryiis.com
Jul 19 '05 #4
Tom,

works like a charme, thank you for the script! I did something wrong when I
wanted to launch the file, but all is working now,

thanks again,

brgds,

Joeri

"Tom Kaminski [MVP]" wrote:
"Joeri Kumbruck" <jo************@dhl.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Hello Tom,

thanks for your help! I've copy/pasted your code, but it doesn't work. I
can't see anything wrong in it, except some variables which are not
defined. Do I need to do anything special to let it work? I can fill in
the fields and press submit, but there is no result showing...


Nothing at all shows? Does any ASP work?

--
Tom Kaminski IIS MVP
http://www.microsoft.com/windowsserv...y/centers/iis/
http://mvp.support.microsoft.com/
http://www.iisfaq.com/
http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS
http://www.tryiis.com


Jul 19 '05 #5
jjsaper0729
4 New Member
Got your script Tom and put it into my login to test. I alwasy get an error like so:

error '8007052e'

/tempscripts/ldaptest2.asp, line 30

line 30 is:

Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, strUserName, strPassword, 0)

I set strADsPath to "WinNT://MYDOMAIN" as well as "LDAP://MYDOMAIN"

Thanks
May 16 '06 #6

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

Similar topics

5
5793
by: Bud | last post by:
I would like to be able to pass a request to IIS to have a user name and password authenticated against my Active Directory Users database. I'm running Server 2003 however my web pages are build...
1
7303
by: anonymous | last post by:
Hi all, I've been searching the way to achieve the following task. But no luck so far. I have a web site(main site), which requires authentication. This authentication is set at Windows...
1
4254
by: Joeri KUMBRUCK | last post by:
Hello, I'm trying to create an ASP page where users can type in a username and password, and these credential should be checked with active directory. If username and password are correct, the...
7
5199
by: Sync Walantaji | last post by:
Hi, I would like to write a asp.net winform program to authenticate users on Active Directory. Can I do this with asp.net if the IIS server is not part of the Active directory domain? Is...
1
2937
by: Christopher | last post by:
We are using forms authentication in our web app and typically query our LDAP Servers by binding to the user node in the LDAP Tree. We usually see the following DN used as the DN for each user.....
1
4523
by: kevin.vaughan | last post by:
Hello Everyone, Is it possible to authenticate the windows password through Active Directory? If so, how would this be done. I have a login screen in my application and am trying to set it up...
3
26606
by: dorrit.Riemenschneider | last post by:
I need to validate a user with username and password against our OpenLDAP active directory. This is my code: Private bool ValidateUser (string username, string password) { DirectoryEntry...
1
13196
by: fomalhaut | last post by:
Hi All, I'm builing an application that requires domain admin access to run, and I'm trying to allow for the application to be run as a normal user and allow the user to provide it with a...
1
3495
by: Michael Howes | last post by:
I would think this would be very, very easy but in the 50 searches I've done I haven't found anything. If our application requires login and that user/password be a local windows account or more...
0
7228
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
7128
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
7393
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...
1
7058
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...
0
5635
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
3206
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...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.