Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
require_once "Auth.php";
4
require_once 'Log.php';
5
require_once 'Log/observer.php';
6
 
7
// Callback function to display login form
8
function loginFunction($username = null, $status = null, &$auth = null)
9
{
10
	/*
11
	 * Change the HTML output so that it fits to your
12
	 * application.
13
	 */
14
	echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">";
15
	echo "Username: <input type=\"text\" name=\"username\"><br/>";
16
	echo "Password: <input type=\"password\" name=\"password\"><br/>";
17
	echo "<input type=\"submit\">";
18
	echo "</form>";
19
}
20
 
21
class Auth_Log_Observer extends Log_observer {
22
 
23
	var $messages = array();
24
 
25
	function notify($event) {
26
 
27
		$this->messages[] = $event;
28
 
29
	}
30
 
31
}
32
 
33
$options = array(
34
	'enableLogging' => true,
35
	array(
36
		'type' => 'Array',
37
		'options' => array(
38
			'cryptType' => 'md5',
39
			'users' => array(
40
				'guest' => md5('password'),
41
			),
42
		),
43
	),
44
	array(
45
		'type' => 'Array',
46
		'options' => array(
47
			'cryptType' => 'md5',
48
			'users' => array(
49
				'admin' => md5('password'),
50
			),
51
		),
52
	),
53
);
54
$a = new Auth("Multiple", $options, "loginFunction");
55
 
56
$infoObserver = new Auth_Log_Observer(AUTH_LOG_INFO);
57
 
58
$a->attachLogObserver($infoObserver);
59
 
60
$debugObserver = new Auth_Log_Observer(AUTH_LOG_DEBUG);
61
 
62
$a->attachLogObserver($debugObserver);
63
 
64
$a->start();
65
 
66
if ($a->checkAuth()) {
67
	/*
68
	 * The output of your site goes here.
69
	 */
70
	print "Authentication Successful.<br/>";
71
}
72
 
73
print '<h3>Logging Output:</h3>'
74
	.'<b>AUTH_LOG_INFO level messages:</b><br/>';
75
 
76
foreach ($infoObserver->messages as $event) {
77
	print $event['priority'].': '.$event['message'].'<br/>';
78
}
79
 
80
print '<br/>'
81
	.'<b>AUTH_LOG_DEBUG level messages:</b><br/>';
82
 
83
foreach ($debugObserver->messages as $event) {
84
	print $event['priority'].': '.$event['message'].'<br/>';
85
}
86
 
87
print '<br/>';
88
 
89
?>