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);
try
{
object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
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;
}
Wednesday, August 8, 2007
Subscribe to:
Post Comments (Atom)
Review Books
- ASP.NET WebService
- Learn VisualStudio.net
- Basic .NET Framework
- Basic C#
- .NET Interview Questions
- C# 2005 Programming
1 comment:
Hi, I was looking for something like your code, but for some reason yours didn't worked to me.
Which version of .NET Fwk are you using? 1.1, 2.0 ?
Thanks!
Post a Comment