<?php

require_once('../../php/definitions.php');


$mysqli = new mysqli(PACKAGE_LOG_DB_SERVER, PACKAGE_LOG_DB_USER, PACKAGE_LOG_DB_PASS, PACKAGE_LOG_DB_NAME);
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

if (!$mysqli->query("DROP PROCEDURE IF EXISTS Login_AgentPassHashReturn") ||
    !$mysqli->query("
	
	CREATE PROCEDURE Login_AgentPassHashReturn(IN useremail VARCHAR(50))
	BEGIN

	DECLARE hash VARCHAR(128) DEFAULT 0;
	
	SELECT `password` FROM `agent` WHERE `email` = useremail LIMIT 1 INTO hash;

	SET hash = SUBSTR(hash, 1, 64);

	SELECT hash AS hash;

	END;
	
	")) {
    echo "Stored procedure creation failed: (" . $mysqli->errno . ") " . $mysqli->error;
}else{
	echo "Stored Procedure Login_AgentPassHashReturn created successfully.";
}

if($mysqli){$mysqli->close();}
?>