'''函數(shù)功能:查詢域用戶信息
'''參數(shù)說明:strAdmin-域管理賬戶;Password-域帳戶密碼;Domain-域服務(wù)器。
'''
''' 參考資料:http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_23947512.html
''' 搜索:Query LDAP For Existing User Classic ASP 在 www.experts-exchange.com
function getADUserData(strAdmin,strPassword,Domain,userName)
If AuthenticateUser(strAdmin,strPassword,Domain)=False Then '如果管理員認(rèn)證失敗則退出此過程
Response.Write "認(rèn)證失敗。"
Exit function
End If
Dim Conn, strRS, RS, strConn
Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.Recordset")
Conn.Provider = "ADsDSOObject"
Conn.Properties("User ID") = strAdmin
Conn.Properties("Password") = strPassword
Conn.Properties("Encrypt Password") = True
strConn = "Active Directory Provider"
Conn.Open strConn , strAdmin, strPassword
strRS = "SELECT name FROM 'LDAP://" & Domain & "' WHERE sAMAccountName = '"&userName&"' ORDER by name "
RS.Open strRS, Conn,1,1
While RS.EOF = False
getADUserData=rs.Fields("name")
RS.MoveNext
Wend
End function
'''函數(shù)功能:驗(yàn)證域用戶賬號(hào)密碼
'''參數(shù)說明:UserName-域賬戶;Password-域帳戶密碼;Domain-域服務(wù)器。
'''返回: 用戶存在且賬號(hào)密碼正確則返回True,否則返回False;
''' 參考資料:http://stackoverflow.com/questions/3894835/ldap-asp-classic-adodb-2147217865-using-ldap-to-talk-to-active-directory
''' 搜索:LDAP + ASP Classic + ADODB 在 stackoverflow
''' 搜索:Getting Started with ASP for ADSI 在 微軟MSDN
function AuthenticateUser(UserName, Password, Domain)
dim strUser
' assume failure
AuthenticateUser = false
strUser = UserName
strPassword = Password
strQuery = "SELECT cn 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
'''調(diào)用:
ADUserName=getADUserData("已知賬戶","已知密碼","yourDomain.com","要查詢的域賬戶")
該文章在 2015/1/6 11:03:47 編輯過