<?php

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

$userName = $_POST['mobName'];
$userPass = $_POST['mobPass'];
$locTime = "";
$shakeTime = "";

$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);

//get loctime and shakeevent form database

//if($resultName -> num_rows > 0 && $resultPass -> num_rows > 0) {
if($resultConnect -> num_rows > 0) {
    
    $sql = "SELECT shakeevent, loctime FROM accounts WHERE username ='$userName'";
    $result = $mysqli->query($sql);

    if ($result -> num_rows > 0) {
        $row = $result->fetch_assoc();
        $shakeTime = $row["shakeevent"];
        $locTime = $row["loctime"];
    }
}

echo $shakeTime."-".$locTime;

//echo $userName."!".$userPass."-"."data check";
$mysqli->close();

?>