Ticker

6/recent/ticker-posts

What is Custom Authentication in Oracle APEX - Javainhand Tutorial

In this Oracle APEX Tutorial, We will explore about the custom authentication in Oracle APEX.

Oracle APEX Tutorial - What is Custom Authentication in Oracle Apex

What is Custom Authentication in Oracle APEX?

Custom Authentication is a just like validation process that recognizing a users identity in Oracle APEX.

For creating custom authentication in oracle apex application. You have to follow the below steps.

Step 1:- Create a table with your_table_name.

CREATE TABLE USER_VALIDATE
(       
 USER_NAME VARCHAR2(100),
PASSWORD VARCHAR2(100),
STATUS CHAR(1),
USER_TYPE NUMBER

)

Step 2:- Create a User Validate Function below code will help out.

create or replace FUNCTION CUSTOM_USER_AUTH2
 (
 P_USER_NAME IN VARCHAR2,
 P_PASSWORD IN  VARCHAR2
 ) 
 RETURN BOOLEAN AS
     V_USER_NAME  USER_VALIDATE.USER_NAME%TYPE;
     V_PASSWORD    USER_VALIDATE.PASSWORD%TYPE;
     V_STATUS     USER_VALIDATE.STATUS%TYPE;
  BEGIN
  
  
     IF P_USER_NAME IS NULL OR P_PASSWORD IS NULL THEN
 APEX_ERROR.ADD_ERROR (
 p_message  => 'PLEASE ENTER USERNAME AND PASSWORD.',
 p_display_location => apex_error.c_inline_with_field,
 p_page_item_name => 'P9999_PASSWORD');
    RETURN FALSE;
     END IF;
     
     
  BEGIN
        SELECT USER_NAME
              ,PASSWORD
              ,STATUS
        INTO   V_USER_NAME
              ,V_PASSWORD
              ,V_STATUS
        FROM   USER_VALIDATE
        WHERE  UPPER(USER_NAME) = UPPER(P_USER_NAME);
     EXCEPTION
        WHEN NO_DATA_FOUND THEN
        APEX_ERROR.ADD_ERROR (
 p_message  => 'USER NOT FOUND',
 p_display_location => apex_error.c_inline_with_field,
 p_page_item_name => 'P9999_PASSWORD');
       RETURN FALSE;
       WHEN OTHERS THEN
 APEX_ERROR.ADD_ERROR (
 p_message  => 'USER NOT FOUND',
 p_display_location => apex_error.c_inline_with_field,
 p_page_item_name => 'P9999_PASSWORD');    
    RETURN FALSE;
     END;
  
  
     IF V_PASSWORD != P_PASSWORD THEN
      APEX_ERROR.ADD_ERROR (
 p_message  => 'USER NOT FOUND',
 p_display_location => apex_error.c_inline_with_field,
 p_page_item_name => 'P9999_PASSWORD');
     RETURN FALSE;
     END IF;
  
     IF V_STATUS != 'Y' THEN
      APEX_ERROR.ADD_ERROR (
 p_message  => 'USER NOT ACTIVE',
 p_display_location => apex_error.c_inline_with_field,
 p_page_item_name => 'P9999_PASSWORD');
     RETURN FALSE;
     END IF;
       

  RETURN TRUE;
     
  END;

Step 3:-Go to Login Page and below paste into your login process.

DECLARE  
v_Result Boolean := False;
Begin
v_Result := CUSTOM_USER_AUTH2(:P9999_USERNAME,:P9999_PASSWORD);
If v_Result = True Then
 -- Redirect to Page 1 (Home Page).
Wwv_Flow_Custom_Auth_Std.Post_Login(
                                    :P9999_USERNAME -- p_User_Name
                                    ,:P9999_PASSWORD -- p_Password
                                    ,v('APP_SESSION') -- p_Session_Id
                                     ,:APP_ID || ':1' -- p_Flow_page

                                            );
Else
 -- Login Failure, redirect to page 101 (Login Page).
Owa_Util.Redirect_Url('f?p=&APP_ID.:101:&SESSION.');
End If;
End;

Also, Below Screenshot helps you out.

Oracle APEX Tutorial - What is Custom Authentication in Oracle APEX


That's all for today, I think(Custom Authentication 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

0 Comments