How to Authenticate LDAP in .NET

Posted on 2009-04-20
Last Modified: 2016-03-02
I would like to authenticate username and passwords for my application on a windows operating system with any directory service.  For example it could be microsoft active directory, Novell eDirecotry, or SunOne.  I already know how to do this code natively for Microsoft Active Direcotry with c#.  ( I totally gave up using ADSI and creating a low level com component)

The way im attempting to authenticate with Novel eDirecotory is i have installed the Mono project.  Inside the mono project they provide you with Novell.Directory.ldap.dll  The code looks somewhat the same as for Microsoft Active Directory.(

For SunOne, i have been told to use the same code as active direcotry, but the ldap connecton string is a little different.(

To complicate my project, most customers use a "Service account:" which means i need to bind with an administrative username and password before i can authenticate a regular username and password.  My questions is in 2 parts.

1) From what I have explained above, is this the correct direction I should be going to authenticate against each individual direcotory service?  

2) I feel that i dont not need to do any of this code at all.  I also feel the stipulation of using a service account is not imporant at all. If all I care about is authenticating a username and password on a windows machine why do i even need to use ldap?  I mean think about it.  When you login to your machine in the morning, you do not have to provide a service account just to login.  I can easily authenticate a username and password at a DOS prompt by using the runas feature and i will be denied or not and could parse the text file.  Im sure there are other ways i could pass a username and password to the windows operating system that i am on and will tell me if a username and password is valid for the domain that it is on.  Am i right?  If so what suggested ways do you guys have?
Question by:mcbain942
    1 Comment
    LVL 1

    Accepted Solution

    We had a website that needed to authenticate a username and password against domain credentials and used the LogonUser API function. Use it for a network logon (one of its arguments is logon type) and all it does is validate credentials, it doesn't do things like load the users profile that runas would. Only caveat is that the service account does require sufficient access to call LogonUser. I suggest you check the MSDN documentation for what that access is though because it varies by OS.

    But this isnt always the best way, u will need local admin in order to make this api call, googling things, if u read this thread they say there is an api call that doesnt not require this AcquireCredentialsHandleNT with is in security.dll  

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Title # Comments Views Activity
    DFS Question 4 19
    exchange 8 31
    Interviewing System Administrator recommended questions 18 48
    VB.Net - Find String in Array 3 17
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 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

    15 Experts available now in Live!

    Get 1:1 Help Now