[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

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

Authentication with AD

Hi guys!

I'm trying to build a login page on my webserver that will authenticate users with my Active Directory...

It dosen't seems to work and I have no idea why...  Here's my code:

'-------------------------------------------------------------------------------------------------------
<%
Option Explicit
Dim oGroup
Dim userName
Dim allowedGroup
Dim userDomain
dim oRootDSE
dim oDomain
dim con
dim com
dim objRootDSE


Set con = CreateObject("ADODB.Connection")
Set com = CreateObject("ADODB.Command")
'Opening the connection
con.Provider = "ADsDSOObject" 'this is the ADSI OLE-DB provider name
con.Open "Active Directory Provider"
'Create a command object for this connection
Set Com.ActiveConnection = con

'Compose a search string
com.CommandText = "select memberof from 'LDAP://DC=MyDomain, DC=com'"' WHERE sAMAccountName =jsmith

'Execute the query'
Set rs = Com.Execute
'--------------------------------------
'Navigate the record set
'--------------------------------------
While Not rs.EOF
 response.Write rs(0)
Wend


      dim objConnection
      dim strSuccursale
      dim strTools
      dim strSizeq
      dim rsDelivery
      dim rsAct
      dim intNoTrx
      dim strFin
      dim strProduct
      dim strColor
      dim rsCombo
      dim rsTools

      dim strActivity
      


      Set objConnection = Server.CreateObject("ADODB.Connection")      

      objConnection.ConnectionTimeout = 15      
      objConnection.CommandTimeout    = 30
      
      objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\BD2\request.mdb;Persist Security Info=False"

      
      if request.Form("blnSubmit") = "true" then
      
            cmdVerifPwd()
      end if
      
      '**************************
      function cmdVerifPwd()
            
            dim strSql
            dim rsPwd
            set rsPwd = Server.CreateObject("ADODB.RecordSet")
            strSql = "Select * from Rep where username ='" & request.Form("tbUser") & "' and password='"   & request.Form("tbPwd") & "'"
'-------------------------------------------------------------------------------------------------------
Any idea what's wrong???

Thanks!
0
polycorjsp
Asked:
polycorjsp
  • 4
  • 4
1 Solution
 
Dirar Abu KteishCommented:
Hi, are u getting an error? if yes, could you post the description?
0
 
polycorjspAuthor Commented:
Active Server Pages (ASP) error 'ASP 0113'

The max amount of time for a script to execute was
exceed, you can change this limit by specifying a
new value for the property server.  Script Time out
or by changing the value for Script Time out.

Looks like there is an infinit loop somewhere???
0
 
Dirar Abu KteishCommented:
While Not rs.EOF
 response.Write rs(0)
 rs.movenext
Wend
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
polycorjspAuthor Commented:
Ok!  Now i'm getting another error message:

Response object, 'ASP 0106 : 80020005'

Erreur de type

/testing2/login.asp, ligne 0

An unhandled data type was encountered.
0
 
Dirar Abu KteishCommented:
"This can happen if you try to set a date column to a value that is not in proper date format, e.g. "UPDATE tableName SET dateColumn='31/31/2002'"...
 it can also happen when using a command object and named constants (e.g. adDate and adLongVarChar);
it's recommend to use a straight EXEC statement against a connection object, rather than go through the hassle and rigorous code required by an ADODB.Command object. "

proberly in your case is the second case which is "using a command object and named constants".
check this out:
 http://support.microsoft.com/default.aspx?scid=kb;en-us;224422
 http://support.microsoft.com/default.aspx?scid=kb;en-us;294271

Hope it helped
0
 
polycorjspAuthor Commented:
I get the following error

Active Directory error '8000500d'

The directory property cannot be found in the cache.

/testing2/login.asp, line 28
'----------------------------------------------------------------------
<%
Option Explicit
Dim con,rs,Com,objADsPath,objDomain
dim allowedGroup
dim oContainer
dim username
Dim oRootDSE
Dim oDSObj
Dim oAuth
Dim oUser
Dim strUsername
dim strNamingContext
dim strPassword
dim strUserADSPath
Dim blnUserExists

Dim adoConnection
Dim adoRecordset
Dim strServerName

test.com : Active directory domain on my system which is

set ldap = Server.CreateObject("IPWorksASP.LDAP")


username= "user@mydomain.com"
allowedGroup = "RequestLogin"

Set objDomain = GetObject ("GC://RootDSE")

0
 
polycorjspAuthor Commented:
Here's the code for my login page...

Hope your going to be able to help me...!

<%
Option Explicit
Dim con,rs,Com,objADsPath,objDomain
dim allowedGroup
dim oContainer
dim username
Dim oRootDSE
Dim oDSObj
Dim oAuth
Dim oUser
Dim strUsername
dim strNamingContext
dim strPassword
dim strUserADSPath
Dim blnUserExists

Dim adoConnection
Dim adoRecordset
Dim strServerName

'test.com : Active directory domain on my system which is

set ldap = Server.CreateObject("IPWorksASP.LDAP")


'username= "username@mydomain.com"
'allowedGroup = "RequestLogin"

'Set objDomain = GetObject ("GC://RootDSE")
'objADsPath = objDomain.Get("defaultNamingContext")
'Set objDomain = Nothing
'Set con = Server.CreateObject("ADODB.Connection")
'con.provider ="ADsDSOObject"
'con.open "Active Directory Provider"
'Set Com = CreateObject("ADODB.Command")
'Set Com.ActiveConnection = con
'Com.CommandText ="select cn from 'LDAP://DC=mydomain, DC=com' WHERE sAMAccountName='username'"
'Set rs = Com.Execute

'While Not rs.EOF'
      'ww rs("cn")
'      rs.movenext
'Wend


'Set oContainer=GetObject("LDAP://DC=mydomain,DC=com")

'EnumerateUsers oContainer

'Compose a search string
'com.CommandText = "select memberof from 'LDAP://DC=mydomain, DC=com'"' WHERE sAMAccountName =username

'--------------------------------------
'Navigate the record set
'--------------------------------------




'rw "fini"
      '*************************************************************
Function rw(str1)
Response.Write "->" & str1
Response.End
 end Function
 
 Function ww(str1)
Response.Write "->" & str1 & "<br>"

 end Function
Sub EnumerateUsers(oCont)

      Dim oUser
      Dim displayName
      Dim group
      Dim userPermitted
      
      userPermitted = false
      
      For Each oUser In oCont
            
            Select Case LCase(oUser.Class)
            Case "user"
            
            
            if oUser.userPrincipalName = username then
                        if oUser.userPassWord= "password" then
                              rw "It works!"
                        else
                              rw "It dosen't work!"      
                        end if
            
                  for each group in oUser.memberOf
                        set oGroup = getobject("LDAP://" & group)                  
                        if oGroup.get("name") = allowedGroup then
                              userPermitted = true
                              rw "it works"
                        end if
                  next
                  if userPermitted = false then
                        'Access denied - Stop page here
                        rw "Access Denied!"
                        
                  end if
            end if
            
            Case "organizationalunit" , "container"
                  EnumerateUsers oUser
            End Select
      Next
End Sub

%>


<HTML>
      <HEAD>
            <TITLE>Mydomain</TITLE>
            <link href="style.css" rel="styleSheet" type="text/css">
            <script language=javascript>
            function changeSrc(strMode){

      
                  var objSou=window.frmFormulaire.imgSubmit;
                  if (strMode=='ON'){
                        
                        objSou.src='images/soumettre_on.bmp'
                        
                        
                  }else
                  {
                        objSou.src='images/soumettre.bmp'
            
                        
                        }      
                  }
      
      function cmdSubmit(){
      window.frmFormulaire.blnSubmit.value='true';
      window.frmFormulaire.submit()
      
      }
</script>
      </HEAD>
      <BODY BGCOLOR="#ffffff">
      <form id=frmFormulaire method=post runat=server name=frmFormulaire action="login.asp">
      <input type=hidden id=blnSubmit name=blnSubmit>

                  <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="80%">

                        <TR>
                              <TD COLSPAN="4" align=right><img src="images/logo.gif"></TD>
                        </TR>
                  </TABLE>
                  <TABLE BORDER="0" CELLPADDING="8" CELLSPACING="0" WIDTH="80%">
                        <TR>
                              <TD WIDTH="155"><img src=""      width="155" height="7" alt=""></TD>
                              <TD WIDTH="100%">
                        
                                    <table border="0"  cellspacing="2" cellpadding="4" width="100%" ID="Table3">
                                          <tr>
                                                <td>
                                                <%      
                                                      if request.Form("blnSubmit")= "true" then
                                                      
                                                               'if Session("rep_no_seq") = "" then%>
                                                                        <div id=divMsg class="validationsummary">Bad username or password.</div>
                                                            <%      'end if
                                                            
                                                      end if
                                                 
                                                %>
                                                      
                                                
                                                </td>
                                          </tr>
                                          <tr>
                                                <td  class=tourBas bgcolor="#e7d59c">UserName</td>
                                          </tr>
                                          <tr>
                                                <td class=tourBas bgcolor="#e7d59c">
                                                      <input type="text" name="tbUser" id=tbUser size="22" >
                                                </td>
                                          </tr>
                                          <tr>
                                                <td></td>
                                          </tr>
                                          <tr>
                                                <td class=tourBas nowrap bgcolor="#e7d59c">Password</td>
                                          </tr>
                                          <tr>
                                                <td  class=tourBas bgcolor="#e7d59c">
                                                      <input type="password" name="tbPwd" size="22" ID="tbPwd">
                                                </td>
                                          </tr>
                                          <tr>
                                                <td></td>
                                          </tr>
                                          <tr>
                                                <td>
                                                      <img name=imgSubmit id=imgSubmit onmouseup="changeSrc('OFF');" onmousedown="changeSrc('ON');" onclick="cmdSubmit();" src="images/soumettre.bmp" >
                                                </td>
                                          </tr>
                                    </table>
                                    <P></P>
                              </TD>
                        </TR>
                  </TABLE>
            </FORM>
      </BODY>
</HTML>
0
 
Dirar Abu KteishCommented:
'8000500d'  error means that the ADSI property cannot be found in the property cache
this problem illustrates that you have to be careful with 'Get' command, the property you ask for must exist , I don't know about the comments but check this:
you have objADsPath = objDomain.Get("defaultNamingContext") try to change it to
objADsPath = objDomain.Get("DefaultNamingContext").
-----------------------------------|-----------------------------
also check oGroup.get("name"), if the "name" property really exist

Check it out and tell me if it works or not


0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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