Check the active directory users using .net

To log in the active director we have to check the user id and password availability.We can achieve it through the following name space


using System.DirectoryServices;


The following code block will reach our target.


public bool GetValidUserId(string UserIdP, string PasswordP, string DomainNameP, out bool IsValidUserP)
{
IsValidUserP = false;
try
{
DirectoryEntry deDirEntry = new DirectoryEntry("LDAP://" + DomainNameP,
UserIdP,PasswordP,AuthenticationTypes.Secure);
if (deDirEntry.Name.IndexOf("exception") != -1)
{
IsValidUserP = false;
}
IsValidUserP = true;
}
catch (Exception ex)
{
IsValidUserP = false;
}
return IsValidUserP;
}


This above code will useful for the projects which are using the active directory users

Thanks
Nathan


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: