Ticker

6/recent/ticker-posts

Custom Captcha/Image Verification in Oracle APEX - Javainhand Tutorial

In this Oracle APEX Tutorial, We will explore about the Custom Captcha/Image Verification in Oracle APEX.

Captcha stands for completely automated public turning test to tell computers and human apart. It is help to identify the real user or machine user.

For generating Custom Captcha in Oracle APEX, We will use wwv_flow image_generator. If you want to access this package then you have to give permission to your database schema.

Note:- This package not available in the Oracle APEX latest versions like 19.1,20.1 or others. I have done this implementation in Oracle APEX 5.1 version. Also don't try this implementation in apex.oracle.com.

If you are currently working on the Oracle APEX 5.1 version then proceeding in this post.

Step 1:- Go to your application login page and create a page item. In my case, P101_CAPTCHA is my page item.

Image Verification in Oracle Apex

Step 2:- Go to the P101_CAPTCHA properties section then find the Advanced section then see post text section in the advanced section. Use the following HTML code in the post text section.

<div style="background-color:#FFF; border:1px solid #ececec; padding:3px;">
<img width="25" height="25",=""src="APEX_050100.wwv_flow_image_generator.get_image?p_position=1&p_sessionid=&APP_SESSION.">
<img width="25" height="25",=""src="APEX_050100.wwv_flow_image_generator.get_image?p_position=2&p_sessionid=&APP_SESSION.">
<img width="25" height="25",=""src="APEX_050100.wwv_flow_image_generator.get_image?p_position=3&p_sessionid=&APP_SESSION.">
<img width="25" height="25",=""src="APEX_050100.wwv_flow_image_generator.get_image?p_position=4&p_sessionid=&APP_SESSION.">
<img width="25" height="25",=""src="APEX_050100.wwv_flow_image_generator.get_image?p_position=5&p_sessionid=&APP_SESSION.">
</div>

After using above HTML code in the item post text section then you will see the following output.

Custom Captcha In Oracle Apex

Step 3:-After display the captcha, now we have to validate that captcha. For this you have to use following PL/SQL code.

DECLARE
   vCount   NUMBER := 0;
BEGIN
      IF TRIM (:P101_CAPTCHA) IS NULL
      THEN
         RAISE_APPLICATION_ERROR (-20001,
                                  'Please Confirm Verification Code.');
      END IF;

      BEGIN
         SELECT 1
           INTO vCount
           FROM APEX_050100.wwv_flow_request_verifications
          WHERE SESSION_ID = :APP_SESSION
           AND VERIFICATION_STRING= :P101_CAPTCHA;

               -- AND SUBSTR (VERIFICATION_STRING, 1, 5) = :P101_CAPTCHA;
      EXCEPTION
         WHEN OTHERS
         THEN
            RAISE_APPLICATION_ERROR (-20001,
                                     'Please Confirm Verification Code.');
      END;

      IF vCount=1
      THEN
         NULL;
      ELSE
         RAISE_APPLICATION_ERROR (-20001,
                                  'Please Confirm Verification Code.');
      END IF;
END;

Step 4:- After using the verification code then We have to display error message to user when captcha have not verified. For this use #SQLERRM_TEXT# in the process error section.

Note 2:-if wwv_flow request verification table does not found error message then you have to give the permission to your database schema.

That's all for today, I think(Custom Captcha/Image Verification in Oracle APEX) post will helpful for you. If you like the post then share your view in the comment box.

We have already upload a video on this topic if you want to watch that video then click here. Please support our youtube channel so we will upload more Oracle APEX Tutorial videos and blog.

Post a Comment

1 Comments

  1. Thank you for the presented method of using captcha. I analyzed it thoroughly in the apex 5.1 environment – it works. But I don't understand one thing. How a row is removed from the table APEX_050100.wwv_flow_request_verifications when a user logs out of the application? From my observations, it appears that this happens automatically after about 1 hour. But how?

    ReplyDelete

If you have any doubts, Please let me know