简体   繁体   English

在PHP中创建新的Active Directory用户帐户时设置密码

[英]Set password when creating a new Active Directory user account in PHP

This PHP script creates enabled user accounts in Active Directory without a password. 该PHP脚本无需密码即可在Active Directory中创建启用的用户帐户。 How do I set the password? 如何设置密码?

<?php
$examplePassword = "34mlrfm$sxkf";
$WinTimestamp = "131196672000000000" //30-09-16 00:00:00

//Create unicode password
function encodePassword($password) {
    $password="\"".$password."\"";
    $encoded="";
    for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000";}
    return $encoded;
}

//Build Active Directory record     
$ldaprecord["accountExpires"] = $winTimestamp;
$ldaprecord["UserAccountControl"] = "544"; //544 - Account enabled, require password change
$ldaprecord['userPassword'] = encodePassword($examplePassword);
$ldaprecoed['otherAttributes'] = "Truncated from question";

$ds = ldap_connect($AD_server); // Connect to Active Directory
if ($ds) {
    ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
    $r = ldap_bind($ds, $AD_Auth_User, $AD_Auth_PWD); //Bind
    $r = ldap_add($ds,$dn,$ldaprecord); //Create account
    ldap_close($ds); //Close connection
}
?>

I've tried different password encoding methoods. 我尝试了不同的密码编码方法。

I've also tried inserting the password into $ldaprecord["unicodepwd"]. 我也尝试将密码插入$ ldaprecord [“ unicodepwd”]。 Which results in "Server is unwilling to perform" error. 从而导致“服务器不愿执行”错误。

I've got it working. 我已经工作了。 You can only set passwords over an SSL connection, thanks @stuartbrand 您只能通过SSL连接设置密码,谢谢@stuartbrand

Either encrypt traffic on 389 using ldap_start_tls() or connect on 636 using $ds = ldap_connect('ldaps://'.$AD_server); 或者使用ldap_start_tls()在389上加密流量,或者使用$ds = ldap_connect('ldaps://'.$AD_server);在636上进行连接$ds = ldap_connect('ldaps://'.$AD_server);

Password should be inserted into the $ldaprecord["unicodepwd"] attribute. 密码应插入$ ldaprecord [“ unicodepwd”]属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM