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 @file_exists("{$this->dir}/.admin");
29 return @filemtime("{$this->dir}/last.log");
33 function login_password_verify($input, $test)
35 if (substr($test, 0, 1) != '$') {
36 # plaintext match for uncrypted passwords
37 return $input === $test;
39 return password_verify($input, $test);
42 function login_setcookie()
45 return setcookie('login', $User['auth'], 0, '/');
48 function login($inuser, $inpass = NULL)
50 if (empty($inuser)) return;
51 if (!isset($inpass)) {
52 @list ($inuser, $inauth) = explode(':', $inuser, 2);
55 # find password data by user name
56 $userdir = 'profile/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($inuser));
57 $pwfile = "$userdir/.passwd";
58 if (!file_exists($pwfile)) return;
59 $usertest = trim(file_get_contents($pwfile));
60 if (!$usertest) return;
63 $authhash = md5($usertest);
65 if (!login_password_verify($inpass, $usertest)) return;
68 if ($inauth !== $authhash) return;
71 if (function_exists('apache_note')) apache_note('user', $inuser);
73 if ($log = @fopen("$userdir/last.log", 'w')) {
74 fwrite($log, "{$_SERVER['REMOTE_ADDR']} {$_SERVER['HTTP_USER_AGENT']}\n");
80 'admin' => file_exists("$userdir/.admin"),
82 'auth' => "$inuser:$authhash",
86 if (isset($_COOKIE['login'])) {
88 $User = login($_COOKIE['login']);