Hey all!
I currently have an ASP login page that checks against AD for authenitcation. It works great, but I am building a new site that requires a little bit more security. I want the form to check against AD for username/password match, but then to also check to see whether or not the username (account) is a member of a particular group in AD. Below is the code I am currently using for AD authenication. If someone can help me modify it to help me reach my desired result, that would rock! I would prefer not to use ASP.Net if possible (internal reasons), so please refrain from suggesting ASP.Net solutions unless that is the absolute only way to achieve this. Thanks!!
Code:
<%
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") <> "csopp" then
strDomain = Request.Form("Domain")
if strDomain = "" then strDomain = "csopp" end if
else
strDomain = "csopp"
end if
strADsPath = strDomain
iFlags = Request.Form("Flags")
strPassword = Request.Form("Password")
strUserName = Request.Form("UserName")
%>
<form action = "loginpage.asp" method = "post" id=form1 name=form1>
<table width="100%" cellpadding="0" class=news1>
<tr align="left" valign="middle">
<td> </td>
<td class=news1><div align="right"><font class="news1"><strong><nob
r>Username
: </n
obr></stro
ng></font>
</div></td
>
<td> </td>
<td> <div align="left">
<input name=UserName type="text" id=UserName2 value="<%response.write strUserName%>" size="40">
</div></td>
</tr>
<tr align="left" valign="middle">
<td> </td>
<td class=news1><div align="right"><font class="news1"><strong>Pass
word:</str
ong></font
></div></t
d>
<td> </td>
<td> <div align="left">
<input type="password" id=Password2 name=Password size = 40 >
</div></td>
</tr>
<tr align="left" valign="middle">
<td> </td>
<td class=news1><div align="right"><font class="news1"><strong>Doma
in:</stron
g></font><
/div></td>
<td> </td>
<td> <div align="left"><font class="news1">csopp </font>
<input name=Domain type="hidden" id=Password3 value="<%response.write strDomain%>" size = 26 >
</div></td>
</tr>
<tr valign="top">
<td colspan="4"> </
td>
</tr>
<tr valign="top">
<td colspan="4"> <div align="center">
<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
(strADsPat
h, tempstr, strPassword, 0)
if not (Err.number = 0) then
Response.Write "You did not enter the correct password<br> or username for the " & strDomain & " domain.<br>Please try again."
'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 "userhome.asp"
end if
end if
%>
Start Free Trial