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

我们的用户存储是名为eDirectory的LDAP服务器。如何使用System.DirectoryServices.Protocols更改用户密码?     
已邀请:
我使用类似的代码连接到基于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);
    
您需要删除密码,然后重新添加。当我这样做时,我使用了Novell的LDAP库。您可能必须使用DirectoryEntry来使其工作。 从eDirectory - LDAP通过ADSI / System.DirectoryServices删除不可读属性 您可能会遇到问题,具体取决于您在eDirectory中使用的密码类型 带eDirectory的LDAP /通用密码8.8 如何通过LDAP更改eDirectory或通用密码 这是一个ldif样本
dn: cn=<myuser>,ou=<myou>,o=<myo>
changetype: modify
replace: userPassword
userPassword: <newPassWord>
    
我同意Per Noalt和Matthew Whited两人的做法。但是有一个重要的导入。 用户密码更改和管理密码更改之间存在差异。 如果替换userPassword,即管理员密码更改,并且根据密码策略,可能会立即使密码失效。 (eDir使用密码到期,然后使用宽限登录计数)。 如果您提供旧密码和新密码,那么您正在执行用户启动的密码重置。     
使用.net开发人员目录服务编程指南一书中的System.DirectoryServices.Protocols,有一个用户更改密码和管理密码更改的代码示例。我假设我出于版权原因无法在此处粘贴代码示例,但如果您对使用System.DirectoryServices.Protocols和System.DirectoryServices感兴趣,我建议您购买该书。     

要回复问题请先登录注册