<?php
/*
* check_login.php - validates a login and sets session variables appropriately
* Monocle Radio
* Version 1.2, Released 09/12/2005
* Copyright (C) 2005 Kurt Gallagher (hide@address.com)
* http://proteankungfu.com/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//First check if this is the admin user
if($_POST['u']==$cfg['admin_user'] && $_POST['p']==$cfg['admin_pass']) {
$_SESSION['id'] = -1;
$_SESSION['perms'] = 2;
$_SESSION['user'] = $cfg['admin_user'];
$_SESSION['auth_code'] = sha1($cfg['admin_user'].$auth_code);
$_SESSION['message'] = '';
// dump_var($_SESSION);
header("Location:$APP_ROOT/playlist/");
//Otherwise check if we should use mysql
} elseif($cfg['mysql_enable']) {
$link = NewADOConnection('mysql');
$link->Connect($cfg['mysql_host'],$cfg['mysql_user'],$cfg['mysql_pass'],$cfg['mysql_db']);
$row = $link->GetRow("select * from users where uname='{$_POST['u']}';");
if(md5($_POST['p'])==$row['pass']) { //We have a winner
$_SESSION['perms'] = $row['access'];
$_SESSION['user'] = $row['uname'];
$_SESSION['id'] = $row['ID'];
$_SESSION['auth_code'] = sha1($row['uname'].$auth_code);
$_SESSION['message'] = '';
header("Location:$APP_ROOT/playlist/");
} else {
$_SESSION['message'] = 'Bad username or password';
header("Location:$APP_ROOT/login/");
}
//And if that doesn't work we reject them
} else {
$_SESSION['message'] = 'Bad username or password';
header("Location:$APP_ROOT/login/");
}
?>