VB.NET App +ADS +DirectoryEntry/Searcher +AuthenticationTypes.Secure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chad Beckner

    #1

    VB.NET App +ADS +DirectoryEntry/Searcher +AuthenticationTypes.Secure

    Hi everyone,

    Sorry for cross posting, but I wanted to try and put this where it would
    be more visible to everyone... :-)

    I need to find a way to be able to search for entries in our ADS tree. I
    have it working, but I have to pass it my username/password in order to
    search it. What I would like to do is pass the username/password to the
    DirectoryEntry as parameters without having to hard code a
    username/password. I know how to get the username, but how can I pass the
    password (i.e. how can I get the password in order to pass it?). For
    example:

    strUsername = "UserA"
    strAuthUsername = "Admin" <--- Hard coded = BAD
    strAuthPassword = "Password" <--- Hard coded = BAD
    strDomain = "ADS"
    strServer = "ads.somewhere. com"
    strFilter = ""

    Public Shared Function GetUser_Directo ryEntry(ByVal strUsername As
    String, ByVal strAuthUsername As String, ByVal strAuthPassword As String,
    ByVal strDomain As String, ByVal strServer As String, ByVal strFilter As
    String) As DirectoryEntry
    Dim strLoginName As String = String.Format(" {0}\{1}",
    strDomain.Trim, strAuthUsername .Trim)
    Dim deSearchRoot As New
    DirectoryEntry( String.Format(" LDAP://{0}", strDomain.Trim) , strLoginName,
    strAuthPassword .Trim, AuthenticationT ypes.Secure)
    Dim de As DirectoryEntry

    Try
    Dim dsUser As DirectorySearch er = New
    DirectorySearch er(deSearchRoot ,
    String.Format(" (&(objectCatego ry=person)(sAMA ccountName={0}) )",
    strUsername.Tri m))
    Dim srcUser As SearchResultCol lection = dsUser.FindAll( )
    If IsNothing(srcUs er) Then
    Throw New Utilities.Excep tionHandler("Co uld not find
    user in ADS tree")
    Else
    de = srcUser(0).GetD irectoryEntry
    End If
    Catch ex As Exception
    Return Nothing
    End Try
    Return de
    End Function

    Thanks for any assistance!

    Chad


  • Scott Allen

    #2
    Re: VB.NET App +ADS +DirectoryEntry/Searcher +Authentication Types.Secure

    On Wed, 5 Oct 2005 11:57:17 -0500, "Chad Beckner" <cbeckner@iupui .edu>
    wrote:
    [color=blue]
    >username/password. I know how to get the username, but how can I pass the
    >password (i.e. how can I get the password in order to pass it?). For
    >example:
    >[/color]

    Hi Chad,

    Are you saying you want to retrieve a user's password given thier
    username? You won't find a way to do that, but you could store the
    username and password in the .config or another configuration file in
    an encrypted form.

    In ASP.NET you could also impersonate a fixed identity by specifying a
    username / password in web.config (and this section also supports
    encryption). Impersonation will work if the identity is trusted on the
    other domain.

    --
    Scott


    Comment

    • Chad Beckner

      #3
      Re: VB.NET App +ADS +DirectoryEntry/Searcher +Authentication Types.Secure

      No, I don't want to retrieve it, but be able to "use" it to query ADS based
      on "their" credentials, instead of having hard coded username & password.

      P.S. This "function" will also be run in ASP.NET, but I also need this to
      work in a WinForm VB.NET app. :-)

      Chad

      "Scott Allen" <scott@nospam.o detocode.com> wrote in message
      news:4sg8k1ha3c o0juj77dn9jshne tuq1slojm@4ax.c om...[color=blue]
      > On Wed, 5 Oct 2005 11:57:17 -0500, "Chad Beckner" <cbeckner@iupui .edu>
      > wrote:
      >[color=green]
      >>username/password. I know how to get the username, but how can I pass the
      >>password (i.e. how can I get the password in order to pass it?). For
      >>example:
      >>[/color]
      >
      > Hi Chad,
      >
      > Are you saying you want to retrieve a user's password given thier
      > username? You won't find a way to do that, but you could store the
      > username and password in the .config or another configuration file in
      > an encrypted form.
      >
      > In ASP.NET you could also impersonate a fixed identity by specifying a
      > username / password in web.config (and this section also supports
      > encryption). Impersonation will work if the identity is trusted on the
      > other domain.
      >
      > --
      > Scott
      > http://www.OdeToCode.com/blogs/scott/
      >[/color]


      Comment

      Working...