<?php
//
// KUrlLogin.php Joomla authentication script
//
// Author: Jaka Konda
// Plugin: KUrlLogin
// Plugin Link: http://dev.bukkit.org/server-mods/kurllogin/
// Contact: minecraft@konda.si

// base64 must be set to true in config (base64: true)

// I recommend that you add IP of your MC server to bottom comented line ( and uncomment)
//( if it's on local network, IP will probaby be your default gateway, otherwise
// try IP of your MC server directly.

//if($_SERVER['REMOTE_ADDR'] != "192.168.1.1") die(0);

include('configuration.php');

if(isset($_GET['user']))
{	
	$_GET['user'] = base64_decode($_GET['user']);
	$cfg = new JConfig;
	
	$c = mysql_connect($cfg->host, $cfg->user, $cfg->password);
	
	if(!$c)
		die('0');
		mysql_select_db($cfg->db, $c);
		
	$q = mysql_query("SELECT id, password FROM " . $cfg->dbprefix . "users WHERE username = '" . mysql_real_escape_string($_GET['user']) . "' LIMIT 1");
	
	while($r = mysql_fetch_assoc($q))
	{	
		$p = explode(':' , $r['password']);
		
		if(isset($_GET['pass']))
		{
			$_GET['pass'] = base64_decode($_GET['pass']);
			if($p[0] == md5($_GET['pass'].$p[1]))
				echo $r['id'];
				
			else
				echo '0';
		}
		
		else
			echo $r['id'];
	}
}
?>
