This function helps to authenticate user in active directory. Can use provide windows authentication in a form authentication websites too.
DNS Name format: "LDAP://DNSName"
private bool ValidateUser(string dnsname,string username,string password)
{
try
{
DirectoryEntry entry = new DirectoryEntry(dnsname, username, password);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
SearchResultCollection results;
mySearcher.Filter = "cn";
results = mySearcher.FindAll();
if (results == null)
{
lblError.Text = "Invalid User";
return false;
}
else
{
lblError.Text = "User Found";
return true;
}
}
catch
{
lblError.Text = "Invalid User";
return false;
}
}
Showing posts with label custom. Show all posts
Showing posts with label custom. Show all posts
Thursday, January 15, 2009
Subscribe to:
Comments (Atom)