2 date_default_timezone_set('Europe/Amsterdam');
6 function __construct($dir)
9 $this->login = basename($dir);
13 function login_password_verify($input, $test)
15 if (substr($test, 0, 1) != '$') {
16 # plaintext match for uncrypted passwords
17 return $input === $test;
19 return password_verify($input, $test);
22 function login_setcookie()
25 return setcookie('login', $User['auth'], 0, '/');
28 function login($inuser, $inpass = NULL)
30 if (empty($inuser)) return;
31 if (!isset($inpass)) {
32 @list ($inuser, $inauth) = explode(':', $inuser, 2);
35 # find password data by user name
36 $userdir = 'profile/'.preg_replace('/[^a-z0-9]+/', '-', strtolower($inuser));
37 $pwfile = "$userdir/.passwd";
38 if (!file_exists($pwfile)) return;
39 $usertest = trim(file_get_contents($pwfile));
40 if (!$usertest) return;
43 $authhash = md5($usertest);
45 if (!login_password_verify($inpass, $usertest)) return;
48 if ($inauth !== $authhash) return;
51 if (function_exists('apache_note')) apache_note('user', $inuser);
53 if ($log = @fopen("$userdir/last.log", 'w')) {
54 fwrite($log, "{$_SERVER['REMOTE_ADDR']} {$_SERVER['HTTP_USER_AGENT']}\n");
60 'admin' => file_exists("$userdir/.admin"),
62 'auth' => "$inuser:$authhash",
66 if (isset($_COOKIE['login'])) {
68 $User = login($_COOKIE['login']);