jquery link

my custom css

slimbox 2

analytics

Tuesday, May 10, 2011

Validate user against LDAP...

    ...
    using System.DirectoryServices;

        ...
        public bool IsValidLDAPUser(string userName, string password, string ldapPath)
        {
            DirectoryEntry entry = new DirectoryEntry(ldapPath, userName, password);
            DirectorySearcher searcher = new DirectorySearcher(entry);
            searcher.SearchScope = SearchScope.OneLevel;

            try
            {
                SearchResult result = searcher.FindOne();
                return result != null ? true : false;
            }
            catch
            {
                return false;
            }
            finally
            {
                if (searcher != null) searcher.Dispose();
                if (entry != null) entry.Dispose();
            }
        }
        ...

No comments:

Post a Comment