add back end PHP code to the repository

This commit is contained in:
Branislav Stojkovic
2016-10-22 12:45:49 +02:00
parent 4738a23fc6
commit 83e7c0b077
14 changed files with 835 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
<?php
$name=$_REQUEST["username"];
$pwd=$_REQUEST["password"];
$machineId=$_REQUEST["machineId"];
if (!$name) {
echo "{\"string\":Username not provided.}";
exit;
}
if (!$pwd) {
echo "{\"string\":Password not provided.}";
exit;
}
if (!$machineId) {
echo "{\"string\":Machine ID not provided.}";
exit;
}
$pwd = hash("ripemd160", $pwd);
// Load help class
require_once("properties.php");
// Load properties
$dbProperties = new Properties();
$propertiesFile = fopen("db.properties", "rb");
$dbProperties->load($propertiesFile);
// Connect to the DB
$username=$dbProperties->getProperty("user");
$password=$dbProperties->getProperty("pass");
$database=$dbProperties->getProperty("db");
$mysqli = new mysqli(localhost,$username,$password,$database);
// Run the query
$sql= "SELECT name FROM diylc_user WHERE name = \"".addslashes($name)."\" AND password = \"".addslashes($pwd)."\"";
if (!$result = $mysqli->query($sql)) {
echo "{\"string\":Error}";
exit;
}
if ($result->num_rows === 0) {
echo "{\"string\":Error}";
} else {
$token = uniqid(addslashes($name), false);
$sql = "UPDATE diylc_user SET last_login = NOW(), machine_id = '".$machineId."', token='".$token."' WHERE name = \"".$name."\"";
$result2 = $mysqli->query($sql);
echo "{\"string\":".$token."}";
}
$result->free();
$mysqli->close();
?>