title: Classic ASP Authenticate Against Active Directory
body: <p>I have a Classic ASP website (sorry!). Some parts of it need to be NT authentication enabled. </p>
  
  <p>I would ideally like to present the user with a nice login form (rather than a browser prompt) which I then authenticate against AD and then do the usual "log in if success, show error if failure"</p>
  
  <p>Is this even possible? I've tried the following on a local computer but not sure how to properly test for success or if it even expands to searching against AD</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form action="test.asp" method="post"&gt;
          Username:
          &lt;input type="text" name="strUserName"&gt;&lt;br&gt;
          Password:
          &lt;input type="password" name="strPassword"&gt;&lt;br&gt;
          &lt;input type="submit" name="btnSubmit"&gt;
      &lt;/form&gt;
      &lt;%
      If Request.Form("strUsername") &lt;&gt; "" Then
          Dim strADsPath
          strADsPath = "WinNT://ARIA"
          strUserName = Request.Form("strUserName")
          strPassword = Request.Form("strPassword")
  
          'Set adObject = GetObject("WinNT:")
          'Set userObject = adObject.OpenDSObject("WinNT://" &amp; domainName, userName, password, ADS_SECURE_AUTHENTICATION)
  
  
          if (not strADsPath= "") then
              Dim oADsObject
              Set oADsObject = GetObject(strADsPath)
  
              response.write "Authenticating...&lt;br&gt;&lt;br&gt;"
  
              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 "&lt;font color='red'&gt;&lt;font size = 5&gt;&lt;u&gt;&lt;b&gt;Authentication has failed...&lt;b&gt;&lt;/u&gt;&lt;/font&gt;&lt;/font&gt;"
                  Session("Auth") = "NO"
              else
                  Response.Write "&lt;font color='blue'&gt;USER AUTHENTICATED!&lt;/font&gt;&lt;br&gt;"
                  Session("Auth") = "YES"
              end if
          end if
      End If
      %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>So once authenticated, is it possible to grab other stuff such as email and groups?</p>
  
  <p>I've tried following <a href="https://stackoverflow.com/questions/6818478/classic-asp-vbscript-2008-r2-error-using-ad-to-authenticate?rq=1">Classic ASP (VBScript), 2008 R2, error using AD to authenticate</a> and tried authenticating against my local machine but it ALWAYS authenticates no matter what I put in. Is it the fact I'm using a local machine mean it just won't work?</p>