[英]C# netcore ldap authentication using Novell.Directory.Ldap.NETStandard library
[英]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.