2016-10-18 5 views
1
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain,"domain","CN=GroupName, DC = domainc, DC = local")) 
{ 
    // validate the credentials 
    try 
    { 
     bool isValid = pc.ValidateCredentials("userName", "password"); 
    } 
    catch (Exception e) 
    { 

    } 
} 

PrincipialContextコンストラクタで、ドメイン名のみを入力すると、ユーザーを検証できます。しかし、CN = "BadGroupNameDoesNotExist"に入れても、ユーザーはまだ真であると検証されます。私はCNのために何を入れても問題ではないようです。PrincipicalContext ActiveDirectoryコンテナ内のユーザーを検証する

なぜですか?私はアクティブなディレクトリが新しく、有効なCNを置くことは、そのグループに属していてもそれが真実ではないと考えられる場合にのみ有効な資格証明を持つだろうと考えていましたか?

+0

あなたは私は現在、それをやっていることで働く何かを掲示する行っているようにCNに渡す必要はありませんAD内のユーザーを検証することについて – MethodMan

答えて

0

あなたはutilsのクラスを作成し、次の方法などを追加してみてください。..

using System.Security; 
using System.DirectoryServices.AccountManagement; 
public struct Credentials 
{ 
    public string Username; 
    public string Password; 
} 
public class Domain_Authentication 
{ 
    public Credentials Credentials; 
    public string Domain; 
    public Domain_Authentication(string Username, string Password, string SDomain) 
    { 
     Credentials.Username = Username; 
     Credentials.Password = Password; 
     Domain = SDomain; 
    } 
    public bool IsValid() 
    { 
     using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, Domain)) 
     { 
      // validate the credentials 
      return pc.ValidateCredentials(Credentials.Username, Credentials.Password); 
     } 
    } 
} 
+0

ユーザーのみが特定のグループに所属していた場合、どのように返されますか? –

+0

たとえば、 'GroupPrincipal group = GroupPrincipal.FindByIdentity(principalContext、" YourGroupName ");'の中で 'GroupPrincipal'を使用すると、必要なプリンシパルが見つかるまでgroup.Membersプロパティを検索できます。 – MethodMan

+0

例 'foreach(group.Membersのプリンシパルprnc)' – MethodMan

関連する問題