Resetting a LDAP user's password in PHP, without the old password, using admin user

时间:2016-04-21 22:46:23

标签: php ldap openldap

I am trying to figure out how to reset a LDAP user password when connected as another user (admin user) in PHP for a password reset feature.

$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)

(aggregated from class methods) This works for resetting a user's password using the old password, but how would you go about doing a password change with another user (admin in this case)?

I think there is something about the LDAP authentication/binding that I am not understanding. Perhaps someone can point me in the right direction.

can I do a ldap_bind before the ldap_modify that will allow me to use user_dn and update the user as the admin user?

Not clear on how this all works.

OpenLDAP is the implementation being used.

1 个答案:

答案 0 :(得分:0)

您可以使用管理员用户的密码/密码拨打ldap_bind,以此(管理员)用户身份建立连接。

PHP手册中的示例

// street view
    let panoramaNear = CLLocationCoordinate2DMake(map_x, map_y)
    let panoView = GMSPanoramaView.panoramaWithFrame(CGRectZero, nearCoordinate:panoramaNear)
    panoView.camera = GMSPanoramaCamera.init(heading: map_heading, pitch: map_pitch, zoom: 1, FOV: map_fov)
    self.view = panoView;