<?php

/*
define ('DB_HOST','mysql.webzcode.com');
define ('DB_NAME','webzcode_imageUpload');

$mobLogName = $_POST['mobName'];
$mobLogPass = $_POST['mobPass'];

$mysqlConn = new mysqli(DB_HOST,$mobLogName,$mobLogPass,DB_NAME);

if ($mysqlConn->connect_error) {
   // die("ERROR: Could not connect. " . $mysqConn->connect_error);
    echo json_encode([
        "Message" => "Could not connect",
        "Status" => "NOCON"
    ]);
} else {
    echo json_encode([
        "Message" => "Connection successful",
        "Status" => "OKCON"
    ]);
}
*/

require '../connForms/acdet.php';

$userName = $_POST['mobName'];
$userPass = $_POST['mobPass'];

$response = "";

$mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);

$userName = $mysqli->real_escape_string($userName);
$userPass = $mysqli->real_escape_string($userPass);

$iterations = 1000;
$salt = count($userName) * 23;
$hashPass = hash_pbkdf2("sha256", $userPass, $salt, $iterations, 25);

/*
//check to see if username if in database table
$sqlName = "SELECT * FROM accounts WHERE username = '$userName'";
$resultName = $mysqli->query($sqlName);

//check to see if password is in database table
$sqlPass = "SELECT * FROM accounts WHERE userpass = '$hashPass'";
$resultPass = $mysqli->query($sqlPass);
*/

//check to see if username and password are in database table
$sqlConnect = "SELECT * FROM accounts WHERE username = '$userName' and userpass = '$hashPass'";
$resultConnect = $mysqli->query($sqlConnect);


//if($resultName -> num_rows > 0 && $resultPass -> num_rows > 0){
if($resultConnect -> num_rows > 0){
    echo json_encode([
        "Message" => "Connection successful",
        "Status" => "OKCON"
    ]);
} else  {
    echo json_encode([
        "Message" => "Could not connect",
        "Status" => "NOCON"
    ]);
}

$mysqli->close();

//echo $response;


   

?>