I recently had to rewrite a legacy library for authenticating users against Active Directory (AD). Having almost no previous knowledge of this type of authentication I turned to Google – assuming that samples and examples would be readily available.
To my surprise (and annoyance) I found that LDAP authentication using C# was rather cumbersome and I couldn’t find a really good example for doing simple authentication. The closest thing I found was this article on the Microsoft support site (most other examples were simply duplicating this code). I wasn’t a big fan of this example either – the code seems to depend on the consumer code calling the methods in the correct order – bad design in my opinion.
So using a combination from the legacy code and this article I wrote a simple class for performing authentication against AD. I would appreciate any comments to point out any possible mistakes or improvements.