Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

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 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
             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.Homedirectory
                    'response.end
                    '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"
          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 = ValidateLoginAgainstActiveDirectory(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-Language" 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("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>
      </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>       &nbsp; 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">
                    &nbsp;<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">&nbsp;<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">&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 >" & 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>
0
Abdu_Allah
Asked:
Abdu_Allah
  • 2
1 Solution
 
masterbakerCommented:
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:

http://www.microsoft.com/windowsserver2003/evaluation/trial/default.mspx

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.

Jeff
0
 
Abdu_AllahAuthor Commented:
>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?!
0
 
masterbakerCommented:
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
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now