繁体   English   中英

"如何使用 Novell.Directory.Ldap.NETStandard 在 c#\/.NET 中更改 LDAP 的密码"

[英]How to change password of LDAP in c#/.NET using Novell.Directory.Ldap.NETStandard

我尝试使用 Novell.Directory.Ldap.NETStandard(最新版本)更改 LDAP 的密码,但它不起作用。

这是我的代码:

      if (Con.Connected)
            Con.Disconnect();


        Con.Connect(_config);


        string userToChange = "myUser";

        LdapAttribute attribute = new LdapAttribute("unicodePwd", password);

        LdapModification modification = new LdapModification(LdapModification.Replace, attribute);

        Connection.Modify(userToChange, modification);

消息错误是:“操作错误”

我能做什么?

首先您必须通过 SSL 连接,然后绑定到 AD

var ldapConn = new LdapConnection();
ldapConn.SecureSocketLayer = true;
ldapConn.UserDefinedServerCertValidationDelegate += (sender, certificate, chain, sslPolicyErrors) => true;
ldapConn.Connect(YOUR_AD_URL, LdapConnection.DefaultSslPort);
ldapConn.Bind(LdapConnection.LdapV3, AD_USER_LOGIN, AD_USER_PASSWORD);

重要的是AD_USER_LOGIN必须包含ROLE ,它可以修改 AD 数据。 然后

ldapConn.Modify(YOUR_DN,
    new LdapModification(
            LdapModification.Replace,
            new LdapAttribute("unicodePwd", Encoding.Unicode.GetBytes($"\"{NEW_PASSWORD}\""))
        )
    );

ldapConn.Disconnect();

将密码用双引号括起来很重要。

https://github.com/dsbenghe/Novell.Directory.Ldap.NETStandard/issues/31

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM