3 Replies Latest reply: Jan 9, 2014 5:16 AM by Pars RSS

    Reference Custom Auth function in login page

    Test2

      Hello, I am using Oracle 11.2.0.3 - APEX 4.2.4.

       

      After creating Custom Auth Scheme. What changes I have to make in the "LOGIN PROCESS" in page 101.

       

      Orignail Source of login process:

       

            apex_authentication.login (p_username => :p101_username, p_password => :p101_password);

       

      I tried this:

       

      return my_authentication (p_username => :p101_username, p_password => :p101_password);

       

      and

       

      my_authentication (p_username => :p101_username, p_password => :p101_password);

       

      But, it did not work.

       

       

      Create or replace function my_authentication (
          p_username in varchar2,
          p_password in varchar2 )
          return boolean
      is
          l_user visitor.username%type := upper(p_username);
          l_pwd visitor.password%type;
          l_id   visitor.id%type;
      begin
          select id  , password
            into l_id, l_pwd
            from visitor
           where username = l_user;
      
      
          return l_pwd = rawtohex(sys.dbms_crypto.hash (
                             sys.utl_raw.cast_to_raw(p_password||l_id||l_user),
                             sys.dbms_crypto.hash_md5 ));
      exception
          when NO_DATA_FOUND then return false;
      end;
      
        • 1. Re: Reference Custom Auth function in login page
          fac586

          849d380e-58ef-4cec-87a4-f35a7973f2a2 wrote:

          Please update your forum profile with a real handle instead of "849d380e-58ef-4cec-87a4-f35a7973f2a2".

          After creating Custom Auth Scheme. What changes I have to make in the "LOGIN PROCESS" in page 101.

          None. Enter the authentication function name in the Authentication Function Name property of the custom authentication scheme.

          • 2. Re: Reference Custom Auth function in login page
            Test2

            Hello, I got a hendler.

            >None. Enter the authentication function name in the Authentication Function Name property of the custom authentication scheme.

             

            That is exactly what I did. However, I found another example using the below Package:

             

            I was able to add a new user. But, not able to login:

             

            The Settings of The Authentication Scheme:

            Authentication Function Name:  fam_auth_pkg.login

            ------------------------------------------------------------------------------------

            Login Process in page 101:

            apex_authentication.login (p_username => :p101_username, p_password => :p101_password);

             

            But, I get this error on the login page:

            1 error has occurred

            • ORA-06550: line 4, column 23: PLS-00306: wrong number or types of arguments in call to 'LOGIN' ORA-06550: line 4, column 1: PL/SQL: Statement ignored

             

            create or replace package FAM_AUTH_PKG as
              PROCEDURE adduser(p_username IN VARCHAR2
                               ,p_password IN VARCHAR2);
              FUNCTION login(p_username IN VARCHAR2
                                   ,p_password IN VARCHAR2) RETURN BOOLEAN;
            END FAM_AUTH_PKG;
            
            
            create or replace PACKAGE BODY FAM_AUTH_PKG IS
              -- private functions 
            
             
              FUNCTION obfuscate(text_in IN VARCHAR2) RETURN RAW IS
                l_returnvalue RAW(16);
              BEGIN
                dbms_obfuscation_toolkit.md5(input => utl_raw.cast_to_raw(text_in), checksum => l_returnvalue);
                RETURN l_returnvalue;
              END obfuscate;
              -- public functions 
            
             
              PROCEDURE adduser(p_username IN VARCHAR2
                               ,p_password IN VARCHAR2) IS
                l_obfuscated_password VISITOR.password%TYPE;
              BEGIN
                l_obfuscated_password := obfuscate(text_in => p_password);
                INSERT INTO visitor
                  ( username
                  ,password)
                VALUES
                  ( p_username
                  ,l_obfuscated_password);
                NULL;
              END adduser;
            
              FUNCTION login(p_username IN VARCHAR2
                                   ,p_password IN VARCHAR2) RETURN BOOLEAN IS
                l_obfuscated_password VISITOR.password%TYPE;
                l_value               NUMBER;
                l_returnvalue         BOOLEAN;
              BEGIN
                l_obfuscated_password := obfuscate(text_in => p_password);
                BEGIN
                  SELECT 1
                    INTO l_value
                    FROM VISITOR
                   WHERE 1 = 1
                     AND upper(VISITOR.username) = upper(p_username)
                     AND VISITOR.password = l_obfuscated_password;
                EXCEPTION
                  WHEN no_data_found
                       OR too_many_rows THEN
                    l_value := 0;
                  WHEN OTHERS THEN
                    l_value := 0;
                END;
                l_returnvalue := l_value = 1;
                RETURN l_returnvalue;
              END login;
            END fam_auth_PKG;
            
            
            • 3. Re: Reference Custom Auth function in login page
              Pars

              849d380e-58ef-4cec-87a4-f35a7973f2a2 wrote:

              refer this blog Duncan Mein's Blog: Custom Authentication / Authorisation Schemes (Part 1)

               

              Pars.