View Single Post
 
Old January 2nd, 2013, 03:05 AM
sonali sonali is offline
Registered User
Points: 43, Level: 1
Points: 43, Level: 1 Points: 43, Level: 1 Points: 43, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default LDAP AD full name and email address based on Logged in user

I am working on the a project where I should be able to get the full name and email address of Logged in User.
And after lot of modification below code works when I give User id and Password.How ever I should be able to get the first name and email address without passing Password.
Do you have any idea how this can be resolved ?I know I need to change something in the connection string.But not sure how I can achieve this.
Can you help me on this ?

<%
'Get AD User full name and Email address
Dim oConn
Sub connActiveDir(sLogonDomain, sLogon, sPassword)
Set oConn = CreateObject("ADODB.Connection")
Set oRS = CreateObject("ADODB.Recordset")
oConn.Open ("Data Source=Active Directory Provider;Provider=ADsDSOObject;" & _
"User ID=" & sLogonDomain & "\" & sLogon & ";password=" & sPassword & ";")
End Sub

Function getDomain()
Set objRootDSE = GetObject("LDAP://RootDSE")
sConfig = objRootDSE.Get("configurationNamingContext")
getDomain = objRootDSE.Get("defaultNamingContext")
End Function

Function getLogon()
getLogon = (Mid(Request.ServerVariables("LOGON_USER"), _
InStrRev(Request.ServerVariables("LOGON_USER"), "\") + 1))
End Function

Function GetUserDetails(sDomain, sLogon)
strNAME="SELECT displayName " & _
"FROM 'LDAP://" & sDomain & "' " & _
"WHERE samaccountname='" & sLogon & "'"
RESPONSE.Write(strName)
'Set oRS = oConn.Execute("SELECT displayName " & _
' "FROM 'LDAP://" & sDomain & "' " & _
' "WHERE samaccountname='" & sLogon & "'")

'If Not oRs.EOF Then
'GetUserDetails = oRs("displayName")
'Else
'GetUserDetails = "No Department Listed"
'End If
End Function


connActiveDir "AD", "SXMALLA;", "Qwest#@!"

' Call a function to simply display the department of a user that is Currently logged on
Response.Write "Your fullname - " & GetUserDetails(getDomain, getLogon)

%>