如何使用System.DirectoryServices.Protocols更改密码

Ron*_*rby 1 .net c# directoryservices ldap edirectory

我们的用户存储是名为eDirectory的LDAP服务器.如何使用System.DirectoryServices.Protocols更改用户密码?

Per*_*alt 5

我使用类似的代码连接到基于Sun One的LDAP来更改用户的密码.(不应该与Novell eDirectory有所不同......)

using System.DirectoryServices.Protocols;
using System.Net;

//...

// Connect to the directory:
LdapDirectoryIdentifier ldi = new LdapDirectoryIdentifier("theServerOrDirectoryName");
// You might need to specify a full DN for "theUsername" (I had to):
NetworkCredential nc = new NetworkCredential("theUsername", "theOldPassword");
// You might need to experiment with setting a different AuthType:
LdapConnection connection = new LdapConnection(ldi, nc, AuthType.Negotiate);

DirectoryAttributeModification modifyUserPassword = new DirectoryAttributeModification();
modifyUserPassword.Operation = DirectoryAttributeOperation.Replace;
modifyUserPassword.Name = "userPassword";
modifyUserPassword.Add("theNewPassword");

ModifyRequest modifyRequest = new ModifyRequest("theUsername", modifyUserPassword);
DirectoryResponse response = connection.SendRequest(modifyRequest);
Run Code Online (Sandbox Code Playgroud)