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 $this->name ?: $this->login;
37 return rtrim(@file_get_contents("{$this->dir}/email.txt"));
42 return @file_exists("{$this->dir}/.admin");
47 return @filemtime("{$this->dir}/last.log");
52 if ($log = @fopen("{$this->dir}/last.log", 'w')) {
53 $line = $_SERVER['REMOTE_ADDR'].' '.$_SERVER['HTTP_USER_AGENT'];
54 fwrite($log, $line."\n");
59 function login_password_verify($input, $test)
61 if (substr($test, 0, 1) != '$') {
62 # plaintext match for uncrypted passwords
63 return $input === $test;
65 return password_verify($input, $test);
68 function login_setcookie()
71 return setcookie('login', $User->auth, 0, '/');
74 function login($inuser, $inpass = NULL)
76 if (empty($inuser)) return;
77 if (!isset($inpass)) {
78 @list ($inuser, $inauth) = explode(':', $inuser, 2);
81 # find password data by user name
82 $userdir = 'profile/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($inuser));
83 $pwfile = "$userdir/.passwd";
84 if (!file_exists($pwfile)) return;
85 $usertest = trim(file_get_contents($pwfile));
86 if (!$usertest) return;
89 $authhash = md5($usertest);
91 if (!login_password_verify($inpass, $usertest)) return;
94 if ($inauth !== $authhash) return;
97 if (function_exists('apache_note')) apache_note('user', $inuser);
99 $user = new User($userdir);
101 $user->pass = $usertest;
102 $user->auth = "$inuser:$authhash";
106 if (isset($_COOKIE['login'])) {
108 $User = login($_COOKIE['login']);