How do I validate Active Directory creds over LDAP + SSL?

前端 未结 4 935
一个人的身影
一个人的身影 2020-12-02 13:46

I\'m trying to use the .NET 3.5 System.DirectoryServices.AccountManagement namespace to validate user credentials against our Active Directory LDAP server

4条回答
  •  自闭症患者
    2020-12-02 14:13

    Maybe this is another way. There's nothing unusual in validate credentials. The ContextOptions must set properly.

    Default value:

    ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing

    Add Ssl:

    ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing | ContextOptions.SecureSocketLayer

    ContextOptions.Negotiate or ContextOptions.SimpleBind is required. Or whatever your server need to perform authentication. ContextOptions only supports OR bit to bit.

    You could try also set the ContextOptions directly this way in ValidateCredentials method.

    using (var pc = new PrincipalContext(ContextType.Domain, "sd.example.com:636", "DC=sd,DC=example,DC=com", ContextOptions.Negotiate | ContextOptions.SecureSocketLayer))
    {
        return pc.ValidateCredentials(_username, _password);
    }
    

    Or

    using (var pc = new PrincipalContext(ContextType.Domain, "sd.example.com:636", "DC=sd,DC=example,DC=com", ContextOptions.Negotiate))
    {
        return pc.ValidateCredentials(_username, _password, ContextOptions.Negotiate | ContextOptions.SecureSocketLayer);
    }
    

提交回复
热议问题