How to get the current user’s Active Directory details in C#

The “pre Windows 2000” name i.e. DOMAIN\SomeBody, the Somebody portion is known as sAMAccountName. So try: using(DirectoryEntry de = new DirectoryEntry(“LDAP://MyDomainController”)) { using(DirectorySearcher adSearch = new DirectorySearcher(de)) { adSearch.Filter = “(sAMAccountName=someuser)”; SearchResult adSearchResult = adSearch.FindOne(); } } [email protected] is the UserPrincipalName, but it isn’t a required field.

Using C# to authenticate user against LDAP

This username, password within this line: DirectoryEntry(“LDAP://myserver/OU=People,O=mycompany”, username, password); should be for an account that has permission for directory lookup. It could be a service account or testing purpose try with your own. This shouldn’t be the user/pass of someone who you are trying to authenticate. If you want to authenticate, you can use following … Read more

How do I validate Active Directory creds over LDAP + SSL?

I was able to validate credentials using the System.DirectoryServices.Protocols namespace, thanks to a co-worker. Here’s the code: // See http://support.microsoft.com/kb/218185 for full list of LDAP error codes const int ldapErrorInvalidCredentials = 0x31; const string server = “sd.example.com:636”; const string domain = “sd.example.com”; try { using (var ldapConnection = new LdapConnection(server)) { var networkCredential = new … Read more

Connecting to LDAP from C# using DirectoryServices

Well, I think your connection string is missing a bit – specifying just the server name isn’t good enough – you also need to specify a “starting point” for your search. In AD, this would typically be something like the “Users” container in your domain, which you’d specify like this in LDAP parlance: LDAP://novellBox.sample.com/cn=Users,dc=YourCompany,dc=com Not … Read more

.Net’s Directory Services throws a strange exception

I had this problem too using IIS Express and VS 2010. What fixed it for me was a comment on another thread. Validate a username and password against Active Directory? but i’ll save you the click and search… 🙂 Just add ContextOpations.Negotiate to you Validate Credentials call like below. bool valid = context.ValidateCredentials(user, pass, ***ContextOptions.Negotiate***); … Read more

How do a LDAP search/authenticate against this LDAP in Java

Another approach is using UnboundID. Its api is very readable and shorter Create a Ldap Connection public static LDAPConnection getConnection() throws LDAPException { // host, port, username and password return new LDAPConnection(“com.example.local”, 389, “[email protected]”, “admin”); } Get filter result public static List<SearchResultEntry> getResults(LDAPConnection connection, String baseDN, String filter) throws LDAPSearchException { SearchResult searchResult; if (connection.isConnected()) … Read more

Display thumbnailPhoto from Active Directory in PHP

This seems to be a JPEG-File, so you should be able to send that data together with the appropriate mime-type to the browser. It should be possible to output that image with something like: <img src=”data:image/jpeg;base64,<?php echo base64_encode($imageString); ?>”/> But it might also be possible to save files of any image format into that thumbnailPhoto … Read more