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

END//
DELIMITER ;

