2016-04-21 35 views
2

我想弄清楚如何在PHP中爲其他用戶(管理員用戶)連接時重置LDAP用戶密碼以獲取密碼重置功能。用PHP重置LDAP用戶的密碼,不使用舊密碼,使用admin用戶

$this->con = ldap_connect($this->server); 
ldap_set_option($this->con, LDAP_OPT_PROTOCOL_VERSION, 3); 

$user_search = ldap_search($this->con, $this->dn,"(|(uid=$user)(mail=$user))"); 
$this->user_get = ldap_get_entries($this->con, $user_search); 
$user_entry = ldap_first_entry($this->con, $user_search); 
$this->user_dn = ldap_get_dn($this->con, $user_entry); 
$this->user_id = $this->user_get[0]["uid"][0]; 

$entry = array(); 
$entry["userPassword"] = "$encoded_newPassword";  
ldap_modify($this->con, $this->user_dn, $entry) 

這適用於重新使用舊密碼的用戶的密碼,但你會如何去這樣做密碼更改與其他用戶(在這種情況下,管理員)(由類的方法彙總)?

我認爲有一些關於LDAP認證/綁定,我不理解。也許有人可以指出我正確的方向。

我可以在ldap_modify之前做一個ldap_bind,它允許我使用user_dn並以admin用戶身份更新用戶嗎?

不清楚這是如何工作的。

OpenLDAP是正在使用的實現。

回答

0

您可以撥打ldap_bind以及管理員用戶的dn /密碼來建立與此(管理員)用戶的連接。從PHP手冊

樣品

// using ldap bind 
$ldaprdn = 'uname';  // ldap rdn or dn 
$ldappass = 'password'; // associated password 

// connect to ldap server 
$ldapconn = ldap_connect("ldap.example.com") 
    or die("Could not connect to LDAP server."); 

if ($ldapconn) { 

    // binding to ldap server 
    $ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass); 

    // verify binding 
    if ($ldapbind) { 
     echo "LDAP bind successful..."; 
    } else { 
     echo "LDAP bind failed..."; 
    } 

} 
相關問題