Horde_Auth_Ldap::resetPassword PHP 메소드

resetPassword() 공개 메소드

Reset a user's password. Used for example when the user does not remember the existing password.
public resetPassword ( string $userId ) : string
$userId string The user id for which to reset the password.
리턴 string The new password on success.
    public function resetPassword($userId)
    {
        if (!empty($this->_params['ad'])) {
            throw new Horde_Auth_Exception(__CLASS__ . ': Updating users is not supported for Active Directory.');
        }
        /* Search for the user's full DN. */
        try {
            $dn = $this->_ldap->findUserDN($userId);
        } catch (Horde_Exception_Ldap $e) {
            throw new Horde_Auth_Exception($e);
        }
        /* Get a new random password. */
        $password = Horde_Auth::genRandomPassword();
        /* Encrypt the new password */
        $entry = array('userpassword' => Horde_Auth::getCryptedPassword($password, '', $this->_params['encryption'], 'true'));
        /* Set the lastchange field */
        $shadow = $this->_lookupShadow($dn);
        if ($shadow['shadowlastchange']) {
            $entry['shadowlastchange'] = floor(time() / 86400);
        }
        /* Update user entry. */
        try {
            $this->_ldap->modify($dn, array('replace' => $entry));
        } catch (Horde_Ldap_Exception $e) {
            throw new Horde_Auth_Exception($e);
        }
        return $password;
    }