【发布时间】:2019-08-14 10:02:10
【问题描述】:
我正在尝试使用 php-ldap 更改 Microsoft 活动目录中的用户密码。问题是当尝试使用ldap_mod_replace 更改密码时,它并没有更改而是重置密码,这不是我想要的,因为我的用户不允许重置自己的密码。
活动目录基于 Microsoft 服务器 2016,我的应用程序在使用 PHP 7.2 的 IIS 网络服务器上运行。
// open LDAP connection
$ldap_connection = $this->connectToActiveDirectory();
if (@ldap_bind($ldap_connection, $this->ldap_username . '@' . env('LDAP_DOMAIN', 'localhost'), $request->oldPassword)) {
// LDAP connection established
$dn = $request->userdn; // distinguished name of user
/*
The DC requires that the password value be specified in a UTF-16 encoded Unicode
string containing the password surrounded by quotation marks, which has been BER-encoded
as an octet string per the Object(Replica-Link) syntax.
*/
$newPassword = "\"" .$request->password. "\"";
$utf16Password = ""; // converted password
$passwordLength = strlen($newPassword);
for ($i = 0; $i < $passwordLength; $i++) {
$utf16Password .= "{$newPassword{$i}}\000";
}
$passwordEntry = array('unicodePwd' => $utf16Password);
// Set new password
if(@ldap_mod_replace($ldap_connection, $dn, $passwordEntry)) {
// Successful
} else {
// Error, probably not enough permissions
return back(); // Redirect user to previous page
}
ldap_unbind($ldap_connection); // Close LDAP connection
return redirect('/logout'); // Redirect user to logout
}
我想更改密码而不是重置密码,但我找不到解决方案。也许你们中的一些人遇到过这个问题,我很感谢您的帮助!
【问题讨论】:
-
更改和重置有什么区别?
-
@GiacomoM 当您重置密码时,您不必知道旧密码,例如管理员会重置密码。更改密码时,您必须知道旧密码。授予用户重置自己密码的权限的问题在于,当他与他的用户一起登录并且他的计算机处于解锁状态时,任何人都可以更改他的密码而无需知道旧密码。
标签: php laravel active-directory ldap