1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: class Passwd_Driver_Http extends Passwd_Driver
17: {
18: 19: 20: 21: 22: 23: 24: 25: 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:
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:
39: foreach ($this->_params['fields'] as $fieldName => $fieldValue) {
40: $req->addPostData($fieldName, $fieldValue);
41: }
42:
43:
44: $result = $req->sendRequest();
45: if ($result instanceof PEAR_Error) {
46: throw new Passwd_Exception($result->getMessage());
47: }
48:
49:
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:
56:
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: