C:\$Recycle.Bin\S-1-5-21-3967099092-2644009230-141905953-500\$RX0XZUC\php\lib\authenticator.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php

    define
('SESSION_NAME''turbosid');
    
//
    
define('ROLES''roles');
    
define('NOBODY_ROLE''nobody');
    
define('USER_ROLE''user');
    
define('ADMIN_ROLE''admin');
    
//
    
define('S_BAD_AUTH''Attempt to connect to an unauthorized session.');
    
define('S_BAD_LOGOUT''Not logged in.');

    class 
turboAuthenticator 
    
{
        var 
$Permissions;

        function 
turboAuthenticator()
        {
            
$this->connect();
        }
        
        function 
unloadSession()
        {
            
$_SESSION = array();
            unset(
$_COOKIE[session_name()]);
            
session_destroy();            
        }
        
        function 
destroySession()
        {
            
//if (isset($_COOKIE[session_name()])) 
            //    setcookie(session_name() ,"",0,"/");
            
setcookie(session_name(), ''time()-42000'/');
            
$this->unloadSession();
            
// ideally we would GC the session data now
        
}
    
        function 
connect()
        {
            
session_name(SESSION_NAME);
            
session_start();
            
$this->permit();
        }
        
        function 
permit()
        {
            if (isset(
$_SESSION[ROLES]))
                
$this->Permissions $_SESSION[ROLES];
            else
                
$this->Permissions = array(NOBODY_ROLE);
        }
        
        function 
permitted($inRole)
        {
            return (
$inRole == NULL || in_array($inRole$this->Permissions));
        }

        function 
assign_roles($inCredentials)
        {
            
$_SESSION[ROLES] = array(NOBODY_ROLE);
            
// need some actual checking of credentials here
            
$_SESSION[ROLES][] = USER_ROLE;
            if (
$inCredentials[0] == ADMIN_ROLE)
                
$_SESSION[ROLES][] = ADMIN_ROLE;
        }

        function 
authorize($inCredentials)
        {
            
$this->unloadSession();
            
session_regenerate_id();
            
session_start();
            
$this->assign_roles($inCredentials);
            
$this->permit();
            return 
$this->Permissions;
        }
        
        function 
logout()
        {
            if (!isset(
$_SESSION[ROLES]))
                
user_error(S_BAD_LOGOUT);
            
$this->destroySession();
            
$this->permit();
            return 
$this->Permissions;
        }
    }

    class 
turboLoginProxy
    
{
        var 
$Authenticator null;
        function 
turboLoginProxy($inAuth)
        {
            
$this->Authenticator $inAuth;
        }
        function 
login($inUser$inPass)
        {
            return 
$this->Authenticator->Authorize(array($inUser$inPass));
        }
        function 
logout($inUser$inPass)
        {
            return 
$this->Authenticator->Logout();
        }
    }

?>