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 return @file_get_contents("{$this->dir}/name.txt");
24 return htmlspecialchars(implode(' & ', explode("\n", $this->rawname)));
29 return @file_exists("{$this->dir}/.admin");
34 return @filemtime("{$this->dir}/last.log");
38 function login_password_verify($input, $test)
40 if (substr($test, 0, 1) != '$') {
41 # plaintext match for uncrypted passwords
42 return $input === $test;
44 return password_verify($input, $test);
47 function login_setcookie()
50 return setcookie('login', $User['auth'], 0, '/');
53 function login($inuser, $inpass = NULL)
55 if (empty($inuser)) return;
56 if (!isset($inpass)) {
57 @list ($inuser, $inauth) = explode(':', $inuser, 2);
60 # find password data by user name
61 $userdir = 'profile/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($inuser));
62 $pwfile = "$userdir/.passwd";
63 if (!file_exists($pwfile)) return;
64 $usertest = trim(file_get_contents($pwfile));
65 if (!$usertest) return;
68 $authhash = md5($usertest);
70 if (!login_password_verify($inpass, $usertest)) return;
73 if ($inauth !== $authhash) return;
76 if (function_exists('apache_note')) apache_note('user', $inuser);
78 if ($log = @fopen("$userdir/last.log", 'w')) {
79 fwrite($log, "{$_SERVER['REMOTE_ADDR']} {$_SERVER['HTTP_USER_AGENT']}\n");
85 'admin' => file_exists("$userdir/.admin"),
87 'auth' => "$inuser:$authhash",
91 if (isset($_COOKIE['login'])) {
93 $User = login($_COOKIE['login']);