Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP page to authenticate username and password with active directory

Reply
Thread Tools

ASP page to authenticate username and password with active directory

 
 
Joeri KUMBRUCK
Guest
Posts: n/a
 
      08-30-2004
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>


 
Reply With Quote
 
 
 
 
Ben Lovell
Guest
Posts: n/a
 
      08-30-2004
Could you just check for membership to a particular role in your AD domain?
If so, this would be much simpler to achieve using the
IPrincipal.IsInRole(...) method.

--
Ben
http://bitarray.co.uk/ben


"Joeri KUMBRUCK" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to authenticate against the Active Directory using forms authentication with password expiration check? Ruggiero, Vince ASP .Net Web Services 0 12-14-2009 09:31 PM
How to authenticate against the Active Directory using forms authentication with password expiration check? Ruggiero, Vince ASP .Net Web Controls 0 12-14-2009 09:30 PM
oracle - authenticate with username and password dave Java 5 01-12-2008 04:55 AM
Check the username and password with the active directory Filip De Backer ASP .Net Security 3 08-29-2005 07:40 AM
ASP page to authenticate username and password with active directory Joeri KUMBRUCK ASP General 4 09-01-2004 08:00 AM



Advertisments