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");
28 function login_password_verify($input, $test)
30 if (substr($test, 0, 1) != '$') {
31 # plaintext match for uncrypted passwords
32 return $input === $test;
34 return password_verify($input, $test);
37 function login_setcookie()
40 return setcookie('login', $User['auth'], 0, '/');
43 function login($inuser, $inpass = NULL)
45 if (empty($inuser)) return;
46 if (!isset($inpass)) {
47 @list ($inuser, $inauth) = explode(':', $inuser, 2);
50 # find password data by user name
51 $userdir = 'profile/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($inuser));
52 $pwfile = "$userdir/.passwd";
53 if (!file_exists($pwfile)) return;
54 $usertest = trim(file_get_contents($pwfile));
55 if (!$usertest) return;
58 $authhash = md5($usertest);
60 if (!login_password_verify($inpass, $usertest)) return;
63 if ($inauth !== $authhash) return;
66 if (function_exists('apache_note')) apache_note('user', $inuser);
68 if ($log = @fopen("$userdir/last.log", 'w')) {
69 fwrite($log, "{$_SERVER['REMOTE_ADDR']} {$_SERVER['HTTP_USER_AGENT']}\n");
75 'admin' => file_exists("$userdir/.admin"),
77 'auth' => "$inuser:$authhash",
81 if (isset($_COOKIE['login'])) {
83 $User = login($_COOKIE['login']);