首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用C# LdapConnection对象更改LDAP中的用户密码

使用C# LdapConnection对象更改LDAP中的用户密码
EN

Stack Overflow用户
提问于 2014-08-23 03:19:56
回答 1查看 3K关注 0票数 1

我正在使用C#客户端连接到OpenLDAP实例。

我需要验证用户是否输入了正确的旧密码。如果验证成功,我需要用新密码更新它们的"userPassword“属性。

我一直在获取DirectoryOperationException: A value in the request is invalid.,代码如下:

代码语言:javascript
复制
public static void UpdateUserPassword(ref UserProfile user, string oldPassword, string newPassword) {

        string connAccountName = ControllerHelper.GetProperty("VSP_SECURITY_PRINCIPAL", true);
        string connAccountPassword = ControllerHelper.GetProperty("VSP_SECURITY_CREDENTIALS", true);

        int myConnectionId;
        LdapConnection ldapConnection;
        lock (_sConnectionTable.SyncRoot) {
            myConnectionId = _getFirstOpenConnectionId();
            ldapConnection = _getConnectionFromPool(ref myConnectionId);//check for null
        }


        try {

            /*Here is where I try to validate the user's old password*/
            ldapConnection.Bind(new NetworkCredential(user.dnName, oldPassword));

            ModifyRequest request = new ModifyRequest(
                    user.dnName,
                    DirectoryAttributeOperation.Replace,
                    "userPassword",
                    newPassword

                );

            ModifyResponse modResponse = (ModifyResponse)ldapConnection.SendRequest(request);

            user.state.successMsg = "Yay it worked!";

        }
        catch (Exception e) {
            user.state.errorMsg = e.Message;

        }
        finally {
            _releaseConnectionToPool(myConnectionId);
        }

    }

任何帮助都将不胜感激。谢谢!

EN

回答 1

Stack Overflow用户

发布于 2014-08-23 05:39:49

我认为你使用的ctor中ModifyRequest的最后一个参数是一个对象数组,而你只传递了一个可能导致错误的值。

我会用这个而不是你的ModifyRequest行

代码语言:javascript
复制
DirectoryAttributeModification modifyUserPassword = new DirectoryAttributeModification();
modifyUserPassword.Operation = DirectoryAttributeOperation.Replace;
modifyUserPassword.Name = "userPassword";
modifyUserPassword.Add(newPassword);

ModifyRequest modifyRequest = new ModifyRequest(user.dnName, modifyUserPassword);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25454144

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档