<?php
	$hostname = 'localhost';
	$username = 'narKampen';
	$pass = 'IfRLzj2HJBXA9eei';
	$database = 'narKampen';
	
	$conn = new mysqli($hostname, $username, $pass, $database);
	if (!$conn) {
		die("Connection Failed. ". mysqli_connect_error());
	}
	mysqli_set_charset($conn,'utf8');
	
	$username = $conn->real_escape_string($_GET['name']);
	
	if ($username == '') {
		echo "Supply values for all required fields";
		return;
	}
	
	$sql = "SELECT id, salt, password FROM users WHERE username = '$username'";
	$result = $conn->query($sql);
	if ($result->num_rows == 1) {
		$data = $result->fetch_assoc();
		$updateLastLoginSql = "UPDATE users SET last_login = NOW() WHERE id = " . $data['id'];
		$conn->query($updateLastLoginSql);
		$returnArray = array('userId' => $data['id'], 'pass' => $data['password'], 'salt' => $data['salt']);
		echo json_encode($returnArray);
	} else {
		echo "";
	}
	$conn->close();
	
?>