Using WindowsPrincipal and WindowsIdentity class provided by .NET System framework, you can validate the username as below:
using System.Security.Principal;
using System.DirectoryServices;
private Boolean AuthenticateWindowsID(String username)
{
WindowsIdentity ident = WindowsIdentity.GetCurrent();
WindowsPrincipal user = new WindowsPrincipal(ident);
using (DirectoryEntry de = new DirectoryEntry("LDAP://" + StripDomain(user.Identity.Name)))
{
using (DirectorySearcher adSearch = new DirectorySearcher(de))
{
adSearch.Filter = "(FirmAccountName=" + username + ")";
SearchResult adSearchResult = adSearch.FindOne();
if (adSearchResult != null)
return true;
}
}
return false;
}