Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp classic 经典ASP根据Active Directory进行身份验证_Asp Classic_Active Directory_Ldap_Ldap Query - Fatal编程技术网

Asp classic 经典ASP根据Active Directory进行身份验证

Asp classic 经典ASP根据Active Directory进行身份验证,asp-classic,active-directory,ldap,ldap-query,Asp Classic,Active Directory,Ldap,Ldap Query,我有一个经典的ASP网站(对不起!)。它的某些部分需要启用NT身份验证 理想情况下,我希望向用户提供一个好的登录表单(而不是浏览器提示),然后根据AD进行身份验证,然后执行通常的“成功登录,失败显示错误” 这可能吗?我在本地计算机上尝试了以下方法,但不确定如何正确地测试成功,或者它是否扩展到搜索广告 <html> <head> </head> <body> <form action="test.asp" method="post"&g

我有一个经典的ASP网站(对不起!)。它的某些部分需要启用NT身份验证

理想情况下,我希望向用户提供一个好的登录表单(而不是浏览器提示),然后根据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>

用户名:

密码:
因此,一旦认证,是否有可能抓取其他东西,如电子邮件和组


我试着跟踪并尝试对我的本地机器进行身份验证,但无论我输入什么,它都会进行身份验证。我使用的是本地机器,这是否意味着它无法工作?

我知道这是一个老问题,但如果有人仍然感兴趣:

这就是我如何根据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
dim domainController:domainController=“yourdc.company.com”
尺寸ldapPort:ldapPort=389
dim startOu:startOu=“DC=company,DC=com”
函数CheckLogin(szUserName,szPassword)
CheckLogin=False
szUserName=trim(“&szUserName”)
dim oCon:Set oCon=Server.CreateObject(“ADODB.Connection”)
oCon.Provider=“ADsDSOObject”
oCon.Properties(“用户ID”)=szUserName
oCon.Properties(“密码”)=szPassword
oCon.打开“ADProvider”
dim oCmd:Set oCmd=Server.CreateObject(“ADODB.Command”)
设置oCmd.ActiveConnection=oCon
'让我们查找非退出用户的邮件地址
dim szDummyQuery:szDummyQuery=“(&(objectCategory=person)(samaccountname=DeGaullesC))”
dim szDummyProperties:szDummyProperties=“邮件”
dim cmd:cmd=“;”&szDummyQuery&“;”&szDummyProperties&“子树”
oCmd.CommandText=cmd
oCmd.Properties(“页面大小”)=100
出错时继续下一步
dim rs:Set rs=oCmd.Execute
如果err.Number=0,则
CheckLogin=true
呼叫rs.Close()
设置rs=无
如果结束
错误转到0
设置oCmd=nothing
端函数
"试验",
dim res:res=CheckLogin(“youradname\youruser”、“yourpassword”)
如果是的话
响应。写入(“登录确定”)
其他的
Response.Write(“登录失败”)
如果结束

您需要进行
匿名身份验证
才能进行此操作,因为您在IIS中传递凭据时不需要进行任何身份验证。请注意,此方法容易受到中间人攻击,我倾向于仅在封闭环境(如公司内部网)中使用此方法,即使这样,它也不是100%安全的。您能进一步说明“中间人”吗情况请提供您自己的用户界面,以便对Active Directory进行身份验证这意味着客户端必须以HTML格式提供其Windows用户名和密码,并以明文形式发布,必须通过在SSL连接上运行您的站点来确保这一点。