Overview

Packages

  • None
  • Passwd

Classes

  • Passwd
  • Passwd_Driver
  • Passwd_Driver_Adsi
  • Passwd_Driver_Composite
  • Passwd_Driver_Expect
  • Passwd_Driver_Expectpecl
  • Passwd_Driver_Horde
  • Passwd_Driver_Http
  • Passwd_Driver_Kolab
  • Passwd_Driver_Ldap
  • Passwd_Driver_Pine
  • Passwd_Driver_Poppassd
  • Passwd_Driver_Procopen
  • Passwd_Driver_Pspasswd
  • Passwd_Driver_Servuftp
  • Passwd_Driver_Smbldap
  • Passwd_Driver_Smbpasswd
  • Passwd_Driver_Soap
  • Passwd_Driver_Sql
  • Passwd_Driver_Vmailmgr
  • Passwd_Driver_Vpopmail
  • Passwd_Exception
  • Passwd_Factory_Driver
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * The Http driver attempts to change a user's password via a web based
 4:  * interface and implements the Passwd_Driver API.
 5:  *
 6:  * Copyright 2000-2012 Horde LLC (http://www.horde.org/)
 7:  *
 8:  * See the enclosed file COPYING for license information (GPL). If you
 9:  * did not receive this file, see http://www.horde.org/licenses/gpl.php.
10:  *
11:  * @todo Convert to use Horde_Http_Client
12:  *
13:  * @author  Michael Rubinsky <mrubinsk@horde.org>
14:  * @package Passwd
15:  */
16: class Passwd_Driver_Http extends Passwd_Driver
17: {
18:     /**
19:      * Changes the user's password.
20:      *
21:      * @param string $username      The user for which to change the password.
22:      * @param string $old_password  The old (current) user password.
23:      * @param string $new_password  The new user password to set.
24:      *
25:      * @throws Passwd_Exception
26:      */
27:     public function changePassword($username, $old_password, $new_password)
28:     {
29:         $req = new HTTP_Request($this->_params['url']);
30:         $req->setMethod(HTTP_REQUEST_METHOD_POST);
31: 
32:         // Add the required fields that most web-based forms would use.
33:         $req->addPostData($this->_params['username'], $username);
34:         $req->addPostData($this->_params['oldPasswd'], $old_password);
35:         $req->addPostData($this->_params['passwd1'], $new_password);
36:         $req->addPostData($this->_params['passwd2'], $new_password);
37: 
38:         // Now add any fields that were passed in _params['fields'].
39:         foreach ($this->_params['fields'] as $fieldName => $fieldValue) {
40:             $req->addPostData($fieldName, $fieldValue);
41:         }
42: 
43:         // Send the request
44:         $result = $req->sendRequest();
45:         if ($result instanceof PEAR_Error) {
46:             throw new Passwd_Exception($result->getMessage());
47:         }
48: 
49:         // Make sure we have a good response code
50:         $responseCode = $req->getResponseCode();
51:         if ($responseCode != 200) {
52:             throw new Passwd_Exception(_("The requested website for changing user passwords could not be reached."));
53:         }
54: 
55:         // We got *some* response from the server, so get the content and
56:         // let's see if we can't figure out if  it was a success or not.
57:         $responseBody = $req->getResponseBody();
58:         if (strpos($responseBody, $this->_params['eval_results']['badPass'])) {
59:             throw new Passwd_Exception(_("Incorrect old password."));
60:         }
61:         if (strpos($responseBody, $this->_params['eval_results']['badUser'])) {
62:             throw new Passwd_Exception(_("The username could not be found."));
63:         }
64:         if (!strpos($responseBody, $this->_params['eval_results']['success'])) {
65:             throw new Passwd_Exception(_("Your password could not be changed."));
66:         }
67:     }
68: }
69: 
API documentation generated by ApiGen