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");
23 function login_password_verify($input, $test)
25 if (substr($test, 0, 1) != '$') {
26 # plaintext match for uncrypted passwords
27 return $input === $test;
29 return password_verify($input, $test);
32 function login_setcookie()
35 return setcookie('login', $User['auth'], 0, '/');
38 function login($inuser, $inpass = NULL)
40 if (empty($inuser)) return;
41 if (!isset($inpass)) {
42 @list ($inuser, $inauth) = explode(':', $inuser, 2);
45 # find password data by user name
46 $userdir = 'profile/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($inuser));
47 $pwfile = "$userdir/.passwd";
48 if (!file_exists($pwfile)) return;
49 $usertest = trim(file_get_contents($pwfile));
50 if (!$usertest) return;
53 $authhash = md5($usertest);
55 if (!login_password_verify($inpass, $usertest)) return;
58 if ($inauth !== $authhash) return;
61 if (function_exists('apache_note')) apache_note('user', $inuser);
63 if ($log = @fopen("$userdir/last.log", 'w')) {
64 fwrite($log, "{$_SERVER['REMOTE_ADDR']} {$_SERVER['HTTP_USER_AGENT']}\n");
70 'admin' => file_exists("$userdir/.admin"),
72 'auth' => "$inuser:$authhash",
76 if (isset($_COOKIE['login'])) {
78 $User = login($_COOKIE['login']);