I am using custom authentication with APEX 4.1.1 and I want to display custom error messages on the login page if authentication fails. In my authentication function I'm using apex_util.set_authenication_result to set a result code (code below). I've tried to use the apex_util.get_authenication_result on the login page to hide and show custom messages but it's not working. I don't believe the apex_util.get_authenication_result is actually obtaining the result? Am I doing something wrong? Is there a better way?
FUNCTION verify_user(
p_username VARCHAR2,
p_password VARCHAR2
) RETURN BOOLEAN
IS
v_ctr NUMBER;
v_id NUMBER;
v_attempts NUMBER;
BEGIN
SELECT COUNT(1) INTO v_ctr FROM users_tbl
WHERE username = TRIM(UPPER(p_username))
AND password = utl_raw.cast_to_raw(dbms_obfuscation_toolkit.md5(input_string => p_password || TRIM(UPPER(p_username))));
IF v_ctr = 1 THEN
SELECT user_id INTO v_id FROM users_tbl WHERE username = TRIM(UPPER(p_username));
UPDATE users_tbl SET login_attempts = 0 WHERE user_id = v_id;
APEX_UTIL.SET_AUTHENTICATION_RESULT(0);
RETURN TRUE;
ELSE
SELECT COUNT(1) INTO v_ctr FROM users_tbl WHERE username = TRIM(UPPER(p_username));
IF v_ctr = 1 THEN
SELECT user_id INTO v_id FROM users_tbl WHERE username = TRIM(UPPER(p_username));
SELECT login_attempts INTO v_attempts FROM users_tbl WHERE user_id = v_id;
IF v_attempts > 5 THEN
APEX_UTIL.SET_AUTHENTICATION_RESULT(2);
RETURN FALSE;
ELSE
UPDATE users_tbl SET login_attempts = login_attempts + 1 WHERE user_id = v_id;
END IF;
END IF;
APEX_UTIL.SET_AUTHENTICATION_RESULT(1);
RETURN FALSE;
END IF;
END verify_user;
Thanks,
Mark