douxianji6104 2019-08-05 07:47
浏览 320

PHP - LDAP在不使用管理员帐户的情况下更改Active Directory中的用户密码

I'm building an application authenticating against MS Active Directory using LDAP. We have a password policy where user passwords expire.

How can I set a user password without using an AD-administrator through ldap in PHP?

I've seen many approaches but all of them use an administrator account which is from my point of view a security risk.

  • 写回答

1条回答 默认 最新

  • dscuu86620 2019-08-05 21:04
    关注

    The documentation for the unicodePwd attribute describes two ways to change a password:

    1. Sending a "delete" and an "add" operation in the same LDAP request. This uses the old password as the authorization to change the password. This is what a user would normally do themselves if they did Ctrl+Alt+Del -> Change password in Windows.
    2. Sending a "replace" operation, which is the same as an administrator resetting the password. This requires that you already authenticated with an account that has permission to reset the password.

    If I understand you correctly, you want to avoid option 2. So the trick will be to send an "add" and "delete" request in the same request. To do that, you can use ldap_modify_batch. In fact, there is an example of it on the documentation page itself:

    <?php
    function adifyPw($pw)
    {
        return iconv("UTF-8", "UTF-16LE", '"' . $pw . '"');
    }
    
    $dn = "cn=Jack Smith-Jones,ou=Wizards,dc=ad,dc=example,dc=com";
    $modifs = [
        [
            "attrib"  => "unicodePwd",
            "modtype" => LDAP_MODIFY_BATCH_REMOVE,
            "values"  => [adifyPw("Tr0ub4dor&3")],
        ],
        [
            "attrib"  => "unicodePwd",
            "modtype" => LDAP_MODIFY_BATCH_ADD,
            "values"  => [adifyPw("correct horse battery staple")],
        ],
    ];
    ldap_modify_batch($connection, $dn, $modifs);
    

    Note that you may have to connect over a secure connection (LDAPS, usually on port 636) for AD to allow this.

    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题