Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1712 jp_milcent 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3
 
4
/**
5
 * Storage driver for use against PEAR website
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * LICENSE: This source file is subject to version 3.01 of the PHP license
10
 * that is available through the world-wide-web at the following URI:
11
 * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
12
 * the PHP License and are unable to obtain it through the web, please
13
 * send a note to license@php.net so we can mail you a copy immediately.
14
 *
15
 * @category   Authentication
16
 * @package    Auth
17
 * @author     Yavor Shahpasov <yavo@netsmart.com.cy>
18
 * @author     Adam Ashley <aashley@php.net>
19
 * @copyright  2001-2006 The PHP Group
20
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
21
 * @version    CVS: $Id: PEAR.php,v 1.1.4.2 2007-11-19 14:54:05 jp_milcent Exp $
22
 * @link       http://pear.php.net/package/Auth
23
 * @since      File available since Release 1.3.0
24
 */
25
 
26
/**
27
 * Include PEAR HTTP_Client.
28
 */
29
require_once 'HTTP/Client.php';
30
/**
31
 * Include Auth_Container base class
32
 */
33
require_once 'Auth/Container.php';
34
 
35
/**
36
 * Storage driver for authenticating against PEAR website
37
 *
38
 * This driver provides a method for authenticating against the pear.php.net
39
 * authentication system.
40
 *
41
 * @category   Authentication
42
 * @package    Auth
43
 * @author     Yavor Shahpasov <yavo@netsmart.com.cy>
44
 * @author     Adam Ashley <aashley@php.net>
45
 * @author     Adam Harvey <aharvey@php.net>
46
 * @copyright  2001-2007 The PHP Group
47
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
48
 * @version    Release: 1.5.4  File: $Revision: 1.1.4.2 $
49
 * @link       http://pear.php.net/package/Auth
50
 * @since      Class available since Release 1.3.0
51
 */
52
class Auth_Container_Pear extends Auth_Container
53
{
54
 
55
    // {{{ Auth_Container_Pear() [constructor]
56
 
57
    /**
58
     * Constructor
59
     *
60
     * Currently does nothing
61
     *
62
     * @return void
63
     */
64
    function Auth_Container_Pear()
65
    {
66
 
67
    }
68
 
69
    // }}}
70
    // {{{ fetchData()
71
 
72
    /**
73
     * Get user information from pear.php.net
74
     *
75
     * This function uses the given username and password to authenticate
76
     * against the pear.php.net website
77
     *
78
     * @param string    Username
79
     * @param string    Password
80
     * @return mixed    Error object or boolean
81
     */
82
    function fetchData($username, $password)
83
    {
84
        $this->log('Auth_Container_PEAR::fetchData() called.', AUTH_LOG_DEBUG);
85
 
86
        $client = new HTTP_Client;
87
 
88
        $this->log('Auth_Container_PEAR::fetchData() getting salt.', AUTH_LOG_DEBUG);
89
        $code = $client->get('https://pear.php.net/rest-login.php/getsalt');
90
        if ($code != 200) {
91
            return PEAR::raiseError('Bad response to salt request.', $code);
92
        }
93
        $resp = $client->currentResponse();
94
        $salt = $resp['body'];
95
 
96
        $this->log('Auth_Container_PEAR::fetchData() calling validate.', AUTH_LOG_DEBUG);
97
        $code = $client->post('https://pear.php.net/rest-login.php/validate',
98
                              array('username' => $username,
99
                                    'password' => md5($salt.md5($password))));
100
        if ($code != 200) {
101
            return PEAR::raiseError('Bad response to validate request.', $code);
102
        }
103
        $resp = $client->currentResponse();
104
 
105
        list($code, $message) = explode(' ', $resp['body'], 1);
106
        if ($code != 8) {
107
            return PEAR::raiseError($message, $code);
108
        }
109
        return true;
110
    }
111
 
112
    // }}}
113
 
114
}
115
?>