我已经为此困扰了几天。我尝试了各种解决方案均无济于事。请帮忙...
问题: 我们有两个域控制器,它们不在我们的管理之下。我们能够通过端口 389 上的 LDAP 进行连接,但无法通过端口 636 安全地连接。
我们正在开发一个系统,以允许使用许多自助服务设施,其中之一是密码恢复工具。这直到重置用户密码为止。
我通过 PHP 手册找到了一些代码,这些代码似乎可以满足我们的需要,但似乎无法使其正常工作。
这是我到目前为止的代码
if ($caller==="change"){
if (($newPword1 === NULL)||($newPword1 === "" )){ return false;}
if (($newPword2 === NULL)||($newPword2 === "" )){ return false;}
if ($newPword1 != $newPword2) {
$result["ERROR"]="1";
$result["DETAILS"]="Your new password and the confirmation must match!";
exit();
}
try {
$adldap = new adLDAP();
} catch (adLDAPException $e) {
$result["ERROR"]="1";
$result["DETAILS"]="An error occurred in adLDAP";
echo json_encode($result);
exit();
}
$userinfo = $adldap->user()->info($username, array("givenname","dn","lockouttime"));
$res = $userinfo[0]["lockouttime"];
$userDN = $userinfo[0]["dn"];
$firstName = $userinfo[0]["givenname"];
$authUser = $adldap->authenticate($username,$currentPword);
if ($authUser){
try {
$adminUsername = $domain."\\".$adminUsername;
$srvDN = "LDAP://".$server."/";
try {
$ADSI = new COM("LDAP:");
} catch (exception $e){
$result["ERROR"]="1";
$result["ERRORmsg"]=$e->getMessage();
echo json_encode($result);
exit();
}
try {
$user = $ADSI->OpenDSObject($srvDN.$userDN, $adminUsername, $adminPassword, 1);
} catch (exception $e){
$result["ERROR"]="2";
$result["ERRORmsg"]= $e->getMessage();
echo json_encode($result);
exit();
}
try { //set password
if ($user){
$result["object"]="Success";
} else {
$result["object"]="Failed";
}
$user->SetPassword($newPword1); //line:114 -> error occurring on this line
$user->SetInfo();
$result["ERROR"]="0";
$result["DETAILS"]="Thank you $firstName[0]<br><strong>Your password has been changed</strong><br><br>This may take up to 30 minutes to take effect depending on your location";
} catch (exception $e) {
$result["ERROR"]="3";
$result["ERRORmsg"]=$e." - ".$e->getMessage();
$result["DETAILS"]="An Error Occurred.";
}
unset($user);
unset($ADSI);
} catch (exception $e){
$result["ERROR"]="1";
$result["DETAILS"]="An Error Occurred in the ADSI COM";
echo json_encode($result);
exit();
}
} else {
if ($res[0] != "0"){
$result["ERROR"]="1";
$result["DETAILS"]="Im sorry $firstName[0].<br>Your account is now locked. Please contact the IT Service Desk for advice";
} else {
$result["ERROR"]="1";
$result["DETAILS"]="Im sorry $firstName[0].<br>Your current password is incorrect";
}
}
在测试中$result["object"]
返回“成功”。但是代码好像失败就$user->SetPassword($newPword1);
行了。
返回的错误是:
ERROR -> "3"
object -> "Success"
ERRORmsg -> "exception 'com_exception' with message '<b>Source:</b> Unknown<br/><b>Description:</b> Unknown' in C:\inetpub\wwwroot\<path>\<filename>.php:114
Stack trace:
#0 C:\inetpub\wwwroot\<path>\<filename>.php(114): variant->SetPassword('P@ssw0rd')
#1 {main} - <b>Source:</b> Unknown<br/><b>Description:</b> Unknown"
DETAILS -> "An Error Occurred."
上面的代码位于 IIS Web 服务器上的 php 文档中,由用户通过 https 的可查看页面调用
你能提供任何建议或指导吗?