2 date_default_timezone_set('Europe/Amsterdam');
6 function __construct($dir)
9 $this->login = basename($dir);
14 return $this->$col = $this->$col(); # run method and cache
19 $name = @file_get_contents("{$this->dir}/name.txt");
20 return htmlspecialchars(implode(' & ', explode("\n", $name)));
25 return @file_exists("{$this->dir}/.admin");
30 return @filemtime("{$this->dir}/last.log");
34 function login_password_verify($input, $test)
36 if (substr($test, 0, 1) != '$') {
37 # plaintext match for uncrypted passwords
38 return $input === $test;
40 return password_verify($input, $test);
43 function login_setcookie()
46 return setcookie('login', $User['auth'], 0, '/');
49 function login($inuser, $inpass = NULL)
51 if (empty($inuser)) return;
52 if (!isset($inpass)) {
53 @list ($inuser, $inauth) = explode(':', $inuser, 2);
56 # find password data by user name
57 $userdir = 'profile/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($inuser));
58 $pwfile = "$userdir/.passwd";
59 if (!file_exists($pwfile)) return;
60 $usertest = trim(file_get_contents($pwfile));
61 if (!$usertest) return;
64 $authhash = md5($usertest);
66 if (!login_password_verify($inpass, $usertest)) return;
69 if ($inauth !== $authhash) return;
72 if (function_exists('apache_note')) apache_note('user', $inuser);
74 if ($log = @fopen("$userdir/last.log", 'w')) {
75 fwrite($log, "{$_SERVER['REMOTE_ADDR']} {$_SERVER['HTTP_USER_AGENT']}\n");
81 'admin' => file_exists("$userdir/.admin"),
83 'auth' => "$inuser:$authhash",
87 if (isset($_COOKIE['login'])) {
89 $User = login($_COOKIE['login']);