2016-04-21 18 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を使用して管理ユーザーとしてユーザーを更新できますか?

これがどのように機能するかは不明です。

OpenLDAPは使用されている実装です。

答えて

0

adminユーザのdn/passwordを使用してldap_bindに電話をかけて、この(admin)ユーザとして接続を確立できます。 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..."; 
    } 

} 
関連する問題