Abdu_Allah
asked on
I need to test this code on Windows server 2000 or 2003?!
Hi, While Windows server 2000 or 2003 is not available for me so I need to test this ASP code on it, this code is just authenticate users against Active Directory and if there an error it writes on the screen otherwise it will write login success:
Just create new asp file and name it as "testad.asp" and put the following code in it.
Thanks.
PLEASE HELP
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
<%
On Error Resume next
Dim ErrorMessege
function IsAdmin(Domain, Username)
'Set grp = GetObject("WinNT://" & Domain & "/" & "Domain Administrators" & ",group")
'If (grp.IsMember("WinNT://" & Domain & "/" & Username)) Then
' IsAdmin = true
' Set grp = nothing
' exit function
'Else
' Set grp = nothing
' IsAdmin = false
'End If
Set grp = Getobject("WinNT://" & Domain & "/" & "Domain Administrators" & ",group")
For Each member In grp.Members
if lcase(member.Name) = lcase(Username) then
IsAdmin = true
Set grp = nothing
exit function
end if
If (member.Class = "Group") Then
For Each obj In member.Members
if lcase(obj.Name) = lcase(Username) then
IsAdmin = true
Set grp = nothing
exit function
end if
Next
End If
Next
Set grp = nothing
IsAdmin = false
end function
function ValidateLoginAgainstActive Directory( Domain, Username, Password, byref txtErr)
Dim SCRIPT_NAME
if Domain = "" then
txtErr = "Domain name cannot be empty"
ValidateLoginAgainstActive Directory = false
exit function
elseif Username = "" then
txtErr = "User name cannot be empty"
ValidateLoginAgainstActive Directory = false
exit function
elseif Password = "" then
txtErr = "Password cannot be empty"
ValidateLoginAgainstActive Directory = false
exit function
end if
Const ADS_SECURE_AUTHENTICATION = 1
On Error Resume Next
Dim authNamespace, authObject
Set authNamespace = GetObject("WinNT:")
Set authObject = authNamespace.OpenDSObject ("WinNT:// " & Domain, Username, Password, ADS_SECURE_AUTHENTICATION)
If Err.Number <> 0 Then
' Authentication process failed
txtErr = "Error Number 3: Wrong User ID or Password"
ValidateLoginAgainstActive Directory = False
exit function
Else
' Authentication process succeseded
Set authNamespace = Getobject("WinNT://" & Domain & "/" & Username & ",user")
If Err.Number <> 0 Then
response.write "<font color=""red"">Error Number 4: " & Err.Description & "</font><br>"
response.end
end if
'response.write authNamespace.Homedirector y
'response.end
'If Err.Number <> 0 Then
' Authentication process failed
'response.write "error"
'ValidateLoginAgainstActiv eDirectory = False
'end if
'Check if user's homedirectory is not empty
response.write authNamespace.Homedirector y & "<br>"
if IsAdmin(Domain,Username) then
response.write "The user is admin"
end if
ValidateLoginAgainstActive Directory = True
End If
Set authNamespace = Nothing
Set authObject = Nothing
End function
'Get System configuration
function TrueFalse(cond)
if cond = true then
TrueFalse = "Y"
else
TrueFalse = "N"
end if
end function
Dim sText
IsPostBack = Request.Form("dologin")
if usr_name = "" then
usr_name = Request.Form("id")
pass = Request.Form("pwd")
domain = Request.Form("Domain")
end if
if usr_name <> "" Then
ValidUser = ValidateLoginAgainstActive Directory( domain, usr_name, pass,ErrorMessege)
if ValidUser = True Then
'It is OK!!!
Response.write "Login success"
Else
sText = ErrorMessege
if sText <> "" then
sText = "<font color=""red"">" & ErrorMessege & "</font>"
else
sText = "<font color=""red"">Wrong User ID or Password</font>"
end if
Response.Write sText
End if
End if%>
<HTML>
<HEAD>
<link href="filemanager.css" rel="stylesheet" type="text/css">
<META http-equiv="Content-Langua ge" content="en">
<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
<TITLE>You need To login</TITLE>
</HEAD>
<BODY TOPMARGIN="40" >
<%
Dim sURL
sURL = Request.ServerVariables("S CRIPT_NAME ")
if Request.ServerVariables("Q UERY_STRIN G") <> "" Then
sURL = sURL & "?" & Request.ServerVariables("Q UERY_STRIN G")
End if
%>
<table cellpadding="0" cellspacing="0" align="center" width="231" >
<tbody><tr width="100%">
<td width="231" > </td>
</tr>
</tbody></table>
<table border="1" bordercolorlight="#c0c0c0" width="231" cellpadding="0" cellspacing="0" align="center">
<tr><td id="loginForm" width="100%">
<form name="form2" action="testad.asp" method="post">
<p> Enter login name and password.</p>
<input name="login_name" type="hidden" >
<table cellspacing="0" >
<tbody><tr>
<td class="name" width="30%"><label for="login_name"><INPUT type="hidden" name="dologin" value="yes">
<B> Login</B></label></td>
<td width="70%"><INPUT name="id" id="login_name" maxlength="501" tabindex="1"
></td>
</tr>
<tr>
<td class="name" width="30%"><label for="passwd"> <B> Password</B></label></td>
<td width="70%"><INPUT name="pwd" id="passwd" maxlength="14" tabindex="2" type="password"></td>
</tr>
<tr>
<td class="name" width="30%"><label for="Domain"> <B> Domain</B></label></td>
<td width="70%"> <select name="Domain" id="Domain" tabindex="3" onChange="MM_jumpMenu('par ent',this, 1)">
<%
'fill domain names in drop down list
Set objIADsContainer = GetObject("WinNT:")
If Err.Number <> 0 Then
response.write "<font color=""red"">Error Number 1: " & Err.Description & "</font><br>"
end if
objIADsContainer.Filter = Array("domain")
For Each objIADsDomain In objIADsContainer
'response.write "<option >" & objIADsDomain.name & "</option>"
response.write "<option >" & objIADsDomain.name & "</option>"
If Err.Number <> 0 Then
response.write "<font color=""red"">Error Number 2: " & Err.Description & "</font><br>"
end if
'response.write "<option >" & "USER-89DC93EC9A"& "</option>"
Next
Set objIADsDomain = Nothing
Set objIADsContainer = Nothing%>
</select>
</td>
</tr>
<tr align="middle">
<td class="name"></td>
<TD align="middle"><P><INPUT class="button" type="submit" value="Login" name="B1" style="WIDTH: 102px; HEIGHT: 23px" size="50"></P></TD>
</tr>
</tr> </table>
</FORM></TD></TR></TBODY>< /TABLE>
<CENTER></CENTER></BODY>
</HTML>
Just create new asp file and name it as "testad.asp" and put the following code in it.
Thanks.
PLEASE HELP
--------------------------
<%
On Error Resume next
Dim ErrorMessege
function IsAdmin(Domain, Username)
'Set grp = GetObject("WinNT://" & Domain & "/" & "Domain Administrators" & ",group")
'If (grp.IsMember("WinNT://" & Domain & "/" & Username)) Then
' IsAdmin = true
' Set grp = nothing
' exit function
'Else
' Set grp = nothing
' IsAdmin = false
'End If
Set grp = Getobject("WinNT://" & Domain & "/" & "Domain Administrators" & ",group")
For Each member In grp.Members
if lcase(member.Name) = lcase(Username) then
IsAdmin = true
Set grp = nothing
exit function
end if
If (member.Class = "Group") Then
For Each obj In member.Members
if lcase(obj.Name) = lcase(Username) then
IsAdmin = true
Set grp = nothing
exit function
end if
Next
End If
Next
Set grp = nothing
IsAdmin = false
end function
function ValidateLoginAgainstActive
Dim SCRIPT_NAME
if Domain = "" then
txtErr = "Domain name cannot be empty"
ValidateLoginAgainstActive
exit function
elseif Username = "" then
txtErr = "User name cannot be empty"
ValidateLoginAgainstActive
exit function
elseif Password = "" then
txtErr = "Password cannot be empty"
ValidateLoginAgainstActive
exit function
end if
Const ADS_SECURE_AUTHENTICATION = 1
On Error Resume Next
Dim authNamespace, authObject
Set authNamespace = GetObject("WinNT:")
Set authObject = authNamespace.OpenDSObject
If Err.Number <> 0 Then
' Authentication process failed
txtErr = "Error Number 3: Wrong User ID or Password"
ValidateLoginAgainstActive
exit function
Else
' Authentication process succeseded
Set authNamespace = Getobject("WinNT://" & Domain & "/" & Username & ",user")
If Err.Number <> 0 Then
response.write "<font color=""red"">Error Number 4: " & Err.Description & "</font><br>"
response.end
end if
'response.write authNamespace.Homedirector
'response.end
'If Err.Number <> 0 Then
' Authentication process failed
'response.write "error"
'ValidateLoginAgainstActiv
'end if
'Check if user's homedirectory is not empty
response.write authNamespace.Homedirector
if IsAdmin(Domain,Username) then
response.write "The user is admin"
end if
ValidateLoginAgainstActive
End If
Set authNamespace = Nothing
Set authObject = Nothing
End function
'Get System configuration
function TrueFalse(cond)
if cond = true then
TrueFalse = "Y"
else
TrueFalse = "N"
end if
end function
Dim sText
IsPostBack = Request.Form("dologin")
if usr_name = "" then
usr_name = Request.Form("id")
pass = Request.Form("pwd")
domain = Request.Form("Domain")
end if
if usr_name <> "" Then
ValidUser = ValidateLoginAgainstActive
if ValidUser = True Then
'It is OK!!!
Response.write "Login success"
Else
sText = ErrorMessege
if sText <> "" then
sText = "<font color=""red"">" & ErrorMessege & "</font>"
else
sText = "<font color=""red"">Wrong User ID or Password</font>"
end if
Response.Write sText
End if
End if%>
<HTML>
<HEAD>
<link href="filemanager.css" rel="stylesheet" type="text/css">
<META http-equiv="Content-Langua
<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
<TITLE>You need To login</TITLE>
</HEAD>
<BODY TOPMARGIN="40" >
<%
Dim sURL
sURL = Request.ServerVariables("S
if Request.ServerVariables("Q
sURL = sURL & "?" & Request.ServerVariables("Q
End if
%>
<table cellpadding="0" cellspacing="0" align="center" width="231" >
<tbody><tr width="100%">
<td width="231" > </td>
</tr>
</tbody></table>
<table border="1" bordercolorlight="#c0c0c0" width="231" cellpadding="0" cellspacing="0" align="center">
<tr><td id="loginForm" width="100%">
<form name="form2" action="testad.asp" method="post">
<p> Enter login name and password.</p>
<input name="login_name" type="hidden" >
<table cellspacing="0" >
<tbody><tr>
<td class="name" width="30%"><label for="login_name"><INPUT type="hidden" name="dologin" value="yes">
<B> Login</B></label></td>
<td width="70%"><INPUT name="id" id="login_name" maxlength="501" tabindex="1"
></td>
</tr>
<tr>
<td class="name" width="30%"><label for="passwd"> <B> Password</B></label></td>
<td width="70%"><INPUT name="pwd" id="passwd" maxlength="14" tabindex="2" type="password"></td>
</tr>
<tr>
<td class="name" width="30%"><label for="Domain"> <B> Domain</B></label></td>
<td width="70%"> <select name="Domain" id="Domain" tabindex="3" onChange="MM_jumpMenu('par
<%
'fill domain names in drop down list
Set objIADsContainer = GetObject("WinNT:")
If Err.Number <> 0 Then
response.write "<font color=""red"">Error Number 1: " & Err.Description & "</font><br>"
end if
objIADsContainer.Filter = Array("domain")
For Each objIADsDomain In objIADsContainer
'response.write "<option >" & objIADsDomain.name & "</option>"
response.write "<option >" & objIADsDomain.name & "</option>"
If Err.Number <> 0 Then
response.write "<font color=""red"">Error Number 2: " & Err.Description & "</font><br>"
end if
'response.write "<option >" & "USER-89DC93EC9A"& "</option>"
Next
Set objIADsDomain = Nothing
Set objIADsContainer = Nothing%>
</select>
</td>
</tr>
<tr align="middle">
<td class="name"></td>
<TD align="middle"><P><INPUT class="button" type="submit" value="Login" name="B1" style="WIDTH: 102px; HEIGHT: 23px" size="50"></P></TD>
</tr>
</tr> </table>
</FORM></TD></TR></TBODY><
<CENTER></CENTER></BODY>
</HTML>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, but I wouldn't have both drives "active" at the same time. I do this on a PC I have at home right now. I have two hard drives, but only one is plugged in with the power and IDE cables at a time. So right now the drive with my Windows 2003 trial server is plugged in so I can experiment with Virtual Server 2005 R2. When I need to boot XP back up, I shut down the PC, open the case, unplug the drive with 2003, and plug in the drive with XP.
Speaking of virtual server... if you wanted to have a PC with several operating systems running at the same time, you might want to consider Microsoft's Virtual PC 2004 or Virtual Server 2005. Either that or VMWare's GSX product (which I believe is free now). This way you could run multiple OS's on the same hardware AT THE SAME TIME. Just make sure you have enough RAM. :)
Jeff
Speaking of virtual server... if you wanted to have a PC with several operating systems running at the same time, you might want to consider Microsoft's Virtual PC 2004 or Virtual Server 2005. Either that or VMWare's GSX product (which I believe is free now). This way you could run multiple OS's on the same hardware AT THE SAME TIME. Just make sure you have enough RAM. :)
Jeff
ASKER
Actually this is a good thought but can I install Windows Server 2003 on another hard disk while XP is installed on the first disk?! if so how can I do that?!