1<?php
2/**
3 * Copyright 2000-2017 Horde LLC (http://www.horde.org/)
4 *
5 * See the enclosed file COPYING for license information (GPL). If you
6 * did not receive this file, see http://www.horde.org/licenses/gpl.
7 *
8 * @category  Horde
9 * @copyright 2000-2017 Horde LLC
10 * @license   http://www.horde.org/licenses/gpl GPL
11 * @package   Passwd
12 */
13
14/**
15 * Driver to change a user's password via a web based interface.
16 *
17 * @author    Michael Rubinsky <mrubinsk@horde.org>
18 * @author    Michael Slusarz <slusarz@horde.org>
19 * @category  Horde
20 * @copyright 2000-2017 Horde LLC
21 * @license   http://www.horde.org/licenses/gpl GPL
22 * @package   Passwd
23 */
24class Passwd_Driver_Http extends Passwd_Driver
25{
26    /**
27     */
28    protected function _changePassword($user, $oldpass, $newpass)
29    {
30        // Add the required fields that most web-based forms would use.
31        // Then add any fields that were passed in _params['fields'].
32        $post_data = array_merge(array(
33            $this->_params['username'] => $user,
34            $this->_params['oldPasswd'] => $oldpass,
35            $this->_params['passwd1'] => $newpass,
36            $this->_params['passwd2'] => $newpass
37        ), $this->_params['fields']);
38
39        // Send the request
40        try {
41            $response = $GLOBALS['injector']->getInstance('Horde_Core_Factory_HttpClient')->create()->post($this->_params['url'], $post_data);
42        } catch (Horde_Http_Exception $e) {
43            throw new Passwd_Exception($e);
44        }
45
46        // Make sure we have a good response code
47        if ($response->code != 200) {
48            throw new Passwd_Exception(_("The requested website for changing user passwords could not be reached."));
49        }
50
51        // We got *some* response from the server, so get the content and
52        // let's see if we can't figure out if  it was a success or not.
53        $body = $response->getBody();
54        if (strpos($body, $this->_params['eval_results']['badPass'])) {
55            throw new Passwd_Exception(_("Incorrect old password."));
56        }
57        if (strpos($body, $this->_params['eval_results']['badUser'])) {
58            throw new Passwd_Exception(_("The username could not be found."));
59        }
60        if (!strpos($body, $this->_params['eval_results']['success'])) {
61            throw new Passwd_Exception(_("Your password could not be changed."));
62        }
63    }
64
65}
66