Advertisement

08.08.2008 at 11:48AM PDT, ID: 23633688 | Points: 500
[x]
Attachment Details

Authenticating against Active Directory with ASP

Asked by barrykeel in Active Server Pages (ASP), Web Languages/Standards, Active Directory

Tags: , ,

I have some asp code that does authenticate against Active Directory. Once Submit is pressed the asp code authenticates and redirects to the redirect page. The problem is that Windows Integrated Authentication against the web directory is no good. The asp page only authenticates the username/password, but when the redirect happens and you do not have permission to the directory you are prompted with the windows logon dialog box. Also, you can directly type the address and go to the directory. Of course doing this uses Windows Integrated Authentication. How do I tie the login page against the directory permisions. In other words, have it work like OWA forms based authentication?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
<TABLE width="100%" cellpadding="0" cellspacing="0" border="0">
     <TR> 
          <TD width="70%">
<p class="heading1">
Please login: </p> 
 
<% 
on error resume next 
 
Dim strDomain 
Dim strADsPath 
Dim strUserName 
Dim strPassword 
Dim iFlags
Dim errorcount
 
errorcount = 0
 
' force the domain
if Request.Form("Domain") <> "yourdomain.com" then
     strDomain = Request.Form("Domain")
     if strDomain = "" then strDomain = "yourdomain.com" end if
else
     strDomain = "yourdomain.com"
end if
 
 
 
strADsPath = strDomain 
iFlags = Request.Form("Flags") 
strPassword = Request.Form("Password") 
strUserName = Request.Form("UserName") 
 
%>
                
<form action = "Login.asp" method = "post" id=form1 name=form1>
                  <table width="46%" cellpadding="1">
                    <tr align="left" valign="middle"> 
                      <td width="15%"></td>
                      <td width="14%"><nobr>User name:&nbsp;</nobr></td>
                      <td width="71%"> <input type="text" id=UserName2 name=UserName size = 26 value=<%response.write strUserName%>> 
                      </td>
                    </tr>
                    <tr align="left" valign="middle"> 
                      <td>&nbsp; </td>
                      <td>Password:</td>
                      <td> <input type="password" id=Password2 name=Password size = 26 > 
                      </td>
                    </tr>
                    <tr align="left" valign="middle"> 
                      <td>&nbsp;</td>
                      <td>Log on to:</td>
                      
            <td> domain 
<input name=Domain type="hidden" id=Password3 value="<%response.write strDomain%>" size = 26 > 
                      </td>
                    </tr>
                    <tr valign="top"> 
                      <td colspan="3"> <div align="right"> 
                          <input type="hidden" id=Flags2 name=Flags size = 10 value = 0>
                          <input type="submit" value="   login   " id=submit12 name=submit1>
                          <input type="reset" name="Reset" value="Reset">
                        </div></td>
                    </tr>
                  </table>
</form>
 
<% 
if (not strUserName= "") then 
 
      strADsPath = "WinNT://" & strADsPath 
      Dim oADsObject  
      Dim tempstr 
      tempstr = strDomain & "\" & strUserName 
 
  
      Set oADsObject = GetObject(strADsPath) 
 
      Dim strADsNamespace 
      Dim oADsNamespace 
      strADsNamespace = left(strADsPath, instr(strADsPath, ":")) 
      set oADsNamespace = GetObject(strADsNamespace) 
      Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, tempstr, strPassword, 0) 
     
           if not (Err.number = 0) then 
                                             
               Response.Write "Please provide a correct login name<br>or system password for the " & strDomain & " domain!<br>" 
                 'response.write err.description & "<p>" 
               if err.number = -2147022987 then ' for account logout
                    Response.write "<strong>Your account has been logged out!</strong>"
                end if
          
          else 
 
            Session("USER_LOGIN") = strUserName
           Session("isLoggedIn") = True
           Session("ValidUser") = True
            response.redirect "main.asp" 
                    
          end if 
 
end if 
%>
          </TD>
        <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
              <TD width="30%" valign="top"><font color="#999999">Please provide 
                your ask.bm account login and password. <br>
                <br>
                Your account will be <strong>logged out</strong> after 3 unsuccessful 
                logon attempts!<br>
                <br>
      </font></TD>
     </TR>
</TABLE>
 
Loading Advertisement...
 
[+][-]08.08.2008 at 12:35PM PDT, ID: 22192954

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.08.2008 at 07:53PM PDT, ID: 22194888

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628