I have the following two implementations of authenticating users with LDAP and LDAPS and I was wondering which was better / more correct. For the record, both of these work on b
@DTI-Matt, in the examples above, you use VerifyServerCertificate
callback that always returns true
. This, essentially, defies the purpose of connecting to LDAP over SSL, as no real certificate check is performed.
While you could implement a real certificate check using X509Chain
and/or X509Certificate2
classes, it seems PrincipalContext
handles the checks for you.
To summarize, both LdapConnection
and PrincipalContext
provide very similar functionality, in means of connecting to an LDAP server over plain or SSL connection. You have to supply LdapConnection
much more hand-written code for it to work properly. On the other hand, PrincipalContext
gives you the same functionality with less code to write by hand.
As a note, connections to port 636 (your default LDAP over SSL port), by non-SSL PrincipalContext
may be explained by the fact this class tries to connect as secure as possible.