Ticker

6/recent/ticker-posts

What is Custom Authentication in Oracle Apex - Javainhand Tutorial

Oracle APEX Tutorial - What is Custom Authentication in Oracle Apex

 Custom Authentication in Oracle Apex

Hello Friends,
Today I will teach you the most important topic in oracle apex, Specially for beginners that is Custom Authentication in Oracle Apex.


Definition of  Custom Authentication:-
Custom Authentication is a just like validation process that recognizing a users identity in oracle apex


Now Follow Below Steps for creating Custom Authentication in your own oracle apex application.

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


For Oracle Apex Video Tutorials:-


Post a comment

0 Comments