2013-10-08 48 views

回答

1

如果你想這樣做對本地系統帳戶,

using (PrincipalContext pc = new PrincipalContext(ContextType.Domain) 
{ 
    if (pc.ValidateCredentials(username, password)) 
    { 
     /* Check group membership */ 
    } 
} 

如果你想要做的對廣告,

public bool AuthenticateUser(string domainName, string userName, 
    string password) 
{ 
    bool ret = false; 

    try 
    { 
    DirectoryEntry de = new DirectoryEntry("LDAP://" + domainName, 
              userName, password); 
    DirectorySearcher dsearch = new DirectorySearcher(de); 
    SearchResult results = null; 

    results = dsearch.FindOne(); 

    ret = true; 
    } 
    catch 
    { 
    ret = false; 
    } 

    return ret; 
} 
相關問題