pee*_*pee 4 ldap active-directory ldap-query asp-classic
我有一个经典的 ASP 网站(对不起!)。它的某些部分需要启用 NT 身份验证。
理想情况下,我想向用户提供一个漂亮的登录表单(而不是浏览器提示),然后我对 AD 进行身份验证,然后执行通常的“如果成功则登录,如果失败则显示错误”
这甚至可能吗?我已经在本地计算机上尝试了以下操作,但不确定如何正确测试是否成功,或者是否扩展到针对 AD 进行搜索
<html>
<head>
</head>
<body>
<form action="test.asp" method="post">
Username:
<input type="text" name="strUserName"><br>
Password:
<input type="password" name="strPassword"><br>
<input type="submit" name="btnSubmit">
</form>
<%
If Request.Form("strUsername") <> "" Then
Dim strADsPath
strADsPath = "WinNT://ARIA"
strUserName = Request.Form("strUserName")
strPassword = Request.Form("strPassword")
'Set adObject = GetObject("WinNT:")
'Set userObject = adObject.OpenDSObject("WinNT://" & domainName, userName, password, ADS_SECURE_AUTHENTICATION)
if (not strADsPath= "") then
Dim oADsObject
Set oADsObject = GetObject(strADsPath)
response.write "Authenticating...<br><br>"
Dim strADsNamespace
Dim oADsNamespace
strADsNamespace = left(strADsPath, instr(strADsPath, ":"))
set oADsNamespace = GetObject(strADsNamespace)
Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, strUserName,strPassword, 0)
if not (Err.number = 0) then
Response.Write "<font color='red'><font size = 5><u><b>Authentication has failed...<b></u></font></font>"
Session("Auth") = "NO"
else
Response.Write "<font color='blue'>USER AUTHENTICATED!</font><br>"
Session("Auth") = "YES"
end if
end if
End If
%>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
那么一旦通过身份验证,是否可以获取其他内容,例如电子邮件和群组?
我试过遵循Classic ASP (VBScript), 2008 R2,使用 AD 进行身份验证时出错,并尝试对我的本地机器进行身份验证,但无论我输入什么,它总是会进行身份验证。这是我使用本地机器的事实吗?只是行不通?
我知道这是一个老问题,但如果有人仍然感兴趣:
这就是我根据 AD 对用户进行身份验证的方式:这是一种使用经过身份验证的 LDAP 查询的间接方法。如果查询失败,则不允许用户对域控制器进行身份验证。
这有点不雅,因为它需要对域控制器进行显式命名。域名(如果您想使用 sam 帐户名称)和搜索起始 DN 的 OU。
dim domainController : domainController = "yourdc.company.com"
dim ldapPort : ldapPort = 389
dim startOu : startOu = "DC=company,DC=com"
Function CheckLogin( szUserName, szPassword)
CheckLogin = False
szUserName = trim( "" & szUserName)
dim oCon : Set oCon = Server.CreateObject("ADODB.Connection")
oCon.Provider = "ADsDSOObject"
oCon.Properties("User ID") = szUserName
oCon.Properties("Password") = szPassword
oCon.Open "ADProvider"
dim oCmd : Set oCmd = Server.CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oCon
' let's look for the mail address of a non exitsting user
dim szDummyQuery : szDummyQuery = "(&(objectCategory=person)(samaccountname=DeGaullesC))"
dim szDummyProperties : szDummyProperties = "mail"
dim cmd : cmd = "<" & "LDAP://" & domainController & ":" & ldapPort & _
"/" & startOu & ">;" & szDummyQuery & ";" & szDummyProperties & ";subtree"
oCmd.CommandText = cmd
oCmd.Properties("Page Size") = 100
on error resume next
dim rs : Set rs = oCmd.Execute
if err.Number = 0 then
CheckLogin = true
call rs.Close()
set rs = nothing
end if
on error goto 0
set oCmd = nothing
End Function
' perform test
dim res : res = CheckLogin( "youradname\youruser", "yourpassword")
if res then
Response.Write( "Login ok")
else
Response.Write( "Login failed")
end if
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10097 次 |
| 最近记录: |