I need to test this code on Windows server 2000 or 2003?!

Posted on 2006-03-31
Last Modified: 2013-12-23
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.


     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
          '          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
                End If          
          Set grp = nothing
         IsAdmin = false
     end function

    function ValidateLoginAgainstActiveDirectory(Domain, Username, Password, byref txtErr)

               Dim SCRIPT_NAME
               if Domain = "" then
                    txtErr = "Domain name cannot be empty"
                    ValidateLoginAgainstActiveDirectory = false
                    exit function
               elseif Username = "" then
                    txtErr = "User name cannot be empty"
                    ValidateLoginAgainstActiveDirectory = false
                    exit function
               elseif Password = "" then
                    txtErr = "Password cannot be empty"
                    ValidateLoginAgainstActiveDirectory = 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"
                    ValidateLoginAgainstActiveDirectory = False
                    exit function

                    ' 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>"
                    end if
                    'response.write authNamespace.Homedirectory
                    'If Err.Number <> 0 Then
                       ' Authentication process failed
                    'response.write "error"
                    'ValidateLoginAgainstActiveDirectory = False
                    'end if
                    'Check if user's homedirectory is not empty
                    response.write authNamespace.Homedirectory & "<br>"
                    if IsAdmin(Domain,Username) then
                       response.write "The user is admin"
                    end if
                    ValidateLoginAgainstActiveDirectory = True
             End If
             Set authNamespace = Nothing
             Set authObject = Nothing


    End function

    'Get System configuration

    function TrueFalse(cond)
          if cond = true then
               TrueFalse = "Y"
               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 = ValidateLoginAgainstActiveDirectory(domain, usr_name, pass,ErrorMessege)
                    if ValidUser = True  Then
                        'It is OK!!!
                        Response.write "Login success"

                              sText = ErrorMessege
                              if sText  <> "" then
                                        sText = "<font color=""red"">" & ErrorMessege & "</font>"
                                        sText = "<font color=""red"">Wrong User ID or Password</font>"
                                   end if
                              Response.Write sText
                     End if
    End if%>

               <link href="filemanager.css" rel="stylesheet" type="text/css">
                  <META http-equiv="Content-Language" content="en">
              <META http-equiv="Content-Type" content="text/html; charset=windows-1252">
              <TITLE>You need To login</TITLE>
         <BODY TOPMARGIN="40" >
         Dim sURL
         sURL = Request.ServerVariables("SCRIPT_NAME")
         if Request.ServerVariables("QUERY_STRING") <> "" Then
              sURL = sURL & "?" & Request.ServerVariables("QUERY_STRING")
         End if

    <table cellpadding="0" cellspacing="0" align="center" width="231" >

       <tbody><tr width="100%">
        <td width="231"  >&nbsp;</td>
     <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>       &nbsp; Enter login name and password.</p>
          <input name="login_name" type="hidden" >
               <table  cellspacing="0" >
                              <td class="name" width="30%"><label for="login_name"><INPUT type="hidden" name="dologin" value="yes">
                    &nbsp;<B> Login</B></label></td>
                    <td width="70%"><INPUT name="id" id="login_name" maxlength="501" tabindex="1"

                    <td class="name" width="30%"><label for="passwd">&nbsp;<B> Password</B></label></td>
                    <td width="70%"><INPUT name="pwd" id="passwd" maxlength="14" tabindex="2" type="password"></td>
                    <td class="name" width="30%"><label for="Domain">&nbsp;<B> Domain</B></label></td>
                    <td width="70%">  <select name="Domain" id="Domain"  tabindex="3" onChange="MM_jumpMenu('parent',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 >" & & "</option>"
                                                  response.write "<option >" & & "</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>"
                                               Set objIADsDomain = Nothing
                                               Set objIADsContainer = Nothing%>
               <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>     </table>          
Question by:Abdu_Allah
    LVL 13

    Accepted Solution

    As harmless as this probably is, I'm not a big fan of running scripts from unknown sources on a server of mine.  However, I did want to pass along some info that you may find useful.

    You can download and install a 180 day trial version of Windows Server 2003 R2, Enterprise Edition from Microsoft.  All you need is a spare PC (or a spare hard drive to throw in an existing PC) to install this and test as much as you want.  Here's the link:

    I actually downloaded this myself about two weeks ago to set up a server at home to play with MS Virtual Server 2005.  I just threw another hard drive in one of my PCs and installed it to that drive.

    Just a thought.

    LVL 3

    Author Comment

    >or a spare hard drive to throw in an existing PC

    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?!
    LVL 13

    Expert Comment

    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. :)


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article is in response to a question ( here at Experts Exchange. The Original Poster (OP) requires a utility that will accept a list of IP addresses …
    This article offers some helpful and general tips for safe browsing and online shopping. It offers simple and manageable procedures that help to ensure the safety of one's personal information and the security of any devices.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now