2 date_default_timezone_set('Europe/Amsterdam');
6 function __construct($dir)
8 if (!file_exists($dir)) {
9 throw new Exception("Gebruiker niet gevonden in $dir");
12 $this->login = basename($dir);
17 return $this->$col = $this->$col(); # run method and cache
22 return rtrim(@file_get_contents("{$this->dir}/name.txt"));
27 return htmlspecialchars(implode(' & ', explode("\n", $this->rawname)));
32 return @file_exists("{$this->dir}/.admin");
37 return @filemtime("{$this->dir}/last.log");
41 function login_password_verify($input, $test)
43 if (substr($test, 0, 1) != '$') {
44 # plaintext match for uncrypted passwords
45 return $input === $test;
47 return password_verify($input, $test);
50 function login_setcookie()
53 return setcookie('login', $User['auth'], 0, '/');
56 function login($inuser, $inpass = NULL)
58 if (empty($inuser)) return;
59 if (!isset($inpass)) {
60 @list ($inuser, $inauth) = explode(':', $inuser, 2);
63 # find password data by user name
64 $userdir = 'profile/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($inuser));
65 $pwfile = "$userdir/.passwd";
66 if (!file_exists($pwfile)) return;
67 $usertest = trim(file_get_contents($pwfile));
68 if (!$usertest) return;
71 $authhash = md5($usertest);
73 if (!login_password_verify($inpass, $usertest)) return;
76 if ($inauth !== $authhash) return;
79 if (function_exists('apache_note')) apache_note('user', $inuser);
81 if ($log = @fopen("$userdir/last.log", 'w')) {
82 fwrite($log, "{$_SERVER['REMOTE_ADDR']} {$_SERVER['HTTP_USER_AGENT']}\n");
88 'admin' => file_exists("$userdir/.admin"),
90 'auth' => "$inuser:$authhash",
94 if (isset($_COOKIE['login'])) {
96 $User = login($_COOKIE['login']);