DROP PROCEDURE IF EXISTS CheckLogin;
DELIMITER //
CREATE PROCEDURE CheckLogin
(
  IN p_pseudo TEXT,
  IN p_password TEXT,
  OUT outputCode INT,
  OUT accountID INT
)    
READS SQL DATA
BEGIN
SET outputCode :=(
    SELECT
    (
        CASE 
            WHEN (
                SELECT
                    COUNT(*)
                FROM
                    membres
                WHERE
                    pseudo = p_pseudo
            ) != 1 THEN 2005
            WHEN (
                SELECT
                    COUNT(*)
                FROM
                    membres
                WHERE
                    pseudo = p_pseudo AND
                    hashedPassword = MD5(p_password)
            ) != 1 THEN 2006
			ELSE 42
        END
    )
);
SET accountID :=(
    SELECT
        ID
    FROM
        membres
    WHERE
        pseudo = p_pseudo AND
        hashedPassword = MD5(p_password)
);

END//
DELIMITER ;

