3 # Copyright (C) 2008 Jason Woofenden
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 function login_get_fields() {
19 $username = format_oneline($_REQUEST['username']);
20 tem_set('username', $username);
22 $password = format_oneline($_REQUEST['password']);
24 $url = format_unix($_REQUEST['url']);
27 return array($username, $password, $url);
30 function login_main() {
31 if(isset($GLOBALS['url'])) {
32 $_REQUEST['url'] = $GLOBALS['url'];
33 tem_set('url', $GLOBALS['url']);
36 if(isset($_REQUEST['username'])) {
37 list($username, $password, $url) = login_get_fields();
39 $row = db_get_row('people', 'id,password', 'where username=%"', $username);
42 list($id, $password_hash) = $row;
44 if($password_hash && check_password($password_hash, $password)) {
45 message("Logged in successfully.");
47 session_set('auth_username', "$id");
49 session_set('auth_admin', 'yes');