.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Code Snippets >> System Process >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

User Validation using LDAP in C#

Posted By:Pankaj Mishra       Posted Date: August 06, 2008    Points: 10    Category: System Process    URL: http://www.dotnetspark.com  

Hi All,

The below function will authenticate user using Active Directory.

public bool IsAuthenticated(string domain, string username, string pwd)


string _path;

string _filterAttribute;

string servername = "ServerName"; // Give the server Name

string domainAndUsername = domain + "\\" + username;

DirectoryEntry entry = new DirectoryEntry("LDAP://" + servername, domainAndUsername, pwd);



object obj = entry.NativeObject;

DirectorySearcher search = new DirectorySearcher(entry);

search.Filter = "(SAMAccountName=" + username + ")";


SearchResult result = search.FindOne();

if (result == null)


return false;


_path = result.Path;

_filterAttribute = ((string)(result.Properties["cn"][0]));


catch (Exception ex)


return false;


return true;


Hope this will help all



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend