$user = $_POST["user"];
$pass = $_POST["password"];
//$sn = isset($_POST['sn']) ? $_POST['sn'] : "";
// authenticate using form variables
$status = authenticate($user, $pass);
// if user/pass combination is correct
if ($status == 0)
// user/pass check failed
{
// redirect to error page
print "
Can not verify your Password. Please try again.
"; // Login error
exit();
}
else if ($status == 1)
{
// initiate a session
session_start();
// register some session variables
session_register("MM");
// including the username
session_register("USER");
$USER = $user;
// add a record into log
header("Location: /../media/titlelist.php?user=$user");
exit();
}
// authenticate id/password against a database
// returns: 0 if id and password is incorrect
// GroupID if username and password are correct
function authenticate($user, $pass)
{
include("../include/dbconfig.php");
// check login and password
// connect and execute query
$connection = mysql_connect($db_host, $db_user, $db_pass) or die ("Unable to connect!");
$query = "SELECT UserName from MM_user WHERE UserName = '$user' AND Password = OLD_PASSWORD('$pass')";
mysql_select_db($db_name);
$result = mysql_query($query, $connection) or die ("Error in query: $query. " . mysql_error());
// if row exists -> user/pass combination is correct
if (mysql_num_rows($result) == 1)
{
return 1;
}
// user/pass combination is wrong
else
{
return 0;
}
}
?>