<?php
require 'acdet.php';

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

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

if($resultName -> num_rows > 0 && $resultPass -> num_rows > 0){
    $response = "conOK";
} else  {
    $response = "conFail";
}

$mysqli->close();

echo $response;

?>