Directory Programming .NET

Active Directory and ADAM programming support for .NET developers
Welcome to Directory Programming .NET Sign in | Join | Help
in Search

How to authenticate user from .net against ADAm user.

Last post 07-06-2009, 9:21 AM by nischaljd. 4 replies.
Sort Posts: Previous Next
  •  06-26-2009, 11:48 AM 6749

    How to authenticate user from .net against ADAm user.

    I have installed ADAM.

    I have a user Test1 with distinguishedName CN=Test1,O=Microsoft,C=US. and password Test1

    In my Asp.net C# code I try to authenticate user

    void UserInActiveDirectory()

    {

    try

    {

    DirectoryEntry deDirEntry = new DirectoryEntry("LDAP://localhost:389/o=Microsoft,c=US", "Test1", "Test1", AuthenticationTypes.None);

    }

    catch (Exception exp)

    {

    string s = "Fail";

    }

    }

     

    But it never trow exception even if i write any invalid username and password.

     

  •  06-26-2009, 1:32 PM 6753 in reply to 6749

    Re: How to authenticate user from .net against ADAm user.

    DirectoryEntry uses the lazy initialization pattern so the constructor does not actually cause the underlying object to connect to the directory.  You must use a method or property (like NativeObject) that forces the connection to the directory.

    I'd suggest looking through the code samples from ch 12 of the book for some ideas on how to do authentication.

  •  06-29-2009, 10:52 AM 6762 in reply to 6753

    Re: How to authenticate user from .net against ADAm user.

    Thanks Joe.

    I am using authintication from Listing 12.2.

    DirectoryEntry root = new DirectoryEntry("LDAP://localhost:389/o=Microsoft,c=US");

    It returns true;

    But when i authenticate for user Test1 who's userPrincipalName ="Test1" and password = "Test1"

    DirectoryEntry root = new DirectoryEntry("LDAP://localhost:389/o=Microsoft,c=US","Test1", "Test1",AuthenticationTypes.SecureSocketsLayer | AuthenticationTypes.FastBind );

    It throws exception   ex.ErrorCode = -2147016694 

    I tried with AuthenticationTypes.None as well as with distinguishedName = "CN=Test1,O=Microsoft,C=US"

    but unsucessfull.

    Is anything more required in this case?


  •  06-29-2009, 1:37 PM 6763 in reply to 6762

    Re: How to authenticate user from .net against ADAm user.

    First, let's verify that you can actually authenticate this user successfully via LDAP at all.

    For this, use ldp.exe from the ADAM program directory (normally c:\windows\adam).  Connect to the server and then do an LDAP "simple" bind using that UPN name and password.  If that works, then we should be able to this to work as well.

    The error code you are getting is actually an operations error which is not a error you should be getting from an authentication check.  If you could show the exact code and the stack trace for the error (and not just the code), that would be helpful.

  •  07-06-2009, 9:21 AM 6782 in reply to 6763

    Re: How to authenticate user from .net against ADAm user.

    Hi Joe,

    My problem is resolved. I appreciate your help.

    Actually,  I was using server name with unnecessary information.

    DirectoryEntry root = new DirectoryEntry("LDAP://localhost:389/o=Microsoft,c=US","Test1", "Test1",AuthenticationTypes.SecureSocketsLayer | AuthenticationTypes.FastBind );

    I do not need "LDAP://localhost:389/o=Microsoft,c=US"

    Instead, I need server name "LDAP://localhost:389".

    Thanks,

    Nischal

     

View as RSS news feed in XML