Authenticate a user against Active Directory including domain trust

Authenticate a user’s credentials with this code against a domain. This also works with a domain trust.

static bool AuthenticateUser(string userName, string password, string domain)

        {

            bool authentic = false;

            try

            {

                DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain,

                    userName, password);

                object nativeObject = entry.NativeObject;

                authentic = true;

            }

            catch (DirectoryServicesCOMException e) { Console.Write(e.Message); }

            return authentic;

        }

Leave a Comment

Your email address will not be published. Required fields are marked *