×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Ldap authentication in classic asp, retrieving givenname, displayname etc

Ldap authentication in classic asp, retrieving givenname, displayname etc

Ldap authentication in classic asp, retrieving givenname, displayname etc

(OP)
Hi There

I am updating an old intranet asp area and need to add an authentication against Active Directory.
Managed to connect and authenticate with AD but can only get the "cn" and the IP.

can some one help? Many thanks

--------------------------------------------------------------------------

<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True

'// 1. Form Validation
Dim Submit, UserName, Password, Domain, Result, Message, strClientIP
Submit = Request.Form("Submit")

If Submit = "Authenticate" Then

'Get the input from your HTML form
UserName = Request.Form("UserName")
Password = Request.Form("Password")
Domain = Request.Form("Domain")
strClientIP = Request.ServerVariables("REMOTE_ADDR")


'Call the AuthenticateUser() function to do the verification process
Result = AuthenticateUser(UserName, Password, Domain)

If Result Then
'If user exist, then redirect to success page
Session("varuser") = UserName
Session("varremote") = strClientIP
Response.Redirect ("success.asp")
Else
'If user don't exist, redirect to error page
Response.Redirect ("error.asp")
End If
End If

'// 2. Authenticate Function
Function AuthenticateUser(UserName, Password, Domain)
Dim strUser, strPassword, strQuery, oConn, cmd, oRS

'Assume Failure
AuthenticateUser = false
strUser = UserName
strPassword = Password

strQuery = "SELECT cn,displayName,mail,sAMAccountName,sn,msexchhidefromaddresslists FROM 'LDAP://" & Domain & "' WHERE objectClass='*'"
Set oConn = server.CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOOBJECT"
oConn.Properties("User ID") = strUser
oConn.Properties("Password") = strPassword
oConn.Properties("Encrypt Password") = true
oConn.open "DS Query", strUser, strPassword

Set cmd = server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = oConn
cmd.CommandText = strQuery

On Error Resume Next
Set oRS = cmd.Execute

If oRS.bof OR oRS.eof Then
AuthenticateUser = False
Else

AuthenticateUser = True
End if

Set oRS = Nothing
Set oConn = nothing
End Function
%>

<html>
<head>
<title>Using Microsoft Active Directory Authentication</title>
</head>
<body>

<form name="DomainAuthentication" method="post">
Username:<input type="text" name="UserName" size="45"></br>
Password:<input type="password" name="Password" size="45"></br>
AD Domain:<input type="hidden" name="Domain" value="MyDomainHere" size="45"></br>
<input name="submit" type="submit" value="Authenticate">
</form>

</body>
</html>


-------------------------------------------------------------------------------

many thanks

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close