Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ldap authentication in classic asp, retrieving givenname, displayname etc

Status
Not open for further replies.

Vitor Fernandes-Neto

IS-IT--Management
Apr 30, 2021
1
0
0
GB
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top