Wednesday, August 28, 2024

Oracle Password Complexity function

 CREATE OR REPLACE function SYS.ora_dex_verify_function

 ( username     varchar2,

   password     varchar2,

   old_password varchar2)

 return boolean IS

   differ  integer;

   lang    varchar2(512);

   message varchar2(512);

   ret     number;

   last_change sys.user$.ptime%type; --DAV4635 minimum_age

   minimum_age number :=1;--DAV4635 minimum_age


begin

   -- Get the cur context lang and use utl_lms for messages- Bug 22730089

   lang := sys_context('userenv','lang');

   lang := substr(lang,1,instr(lang,'_')-1);


   if not ora_complexity_check(password, chars => 8, uppercase => 1,

                           lowercase => 1, digit => 1, special => 1) then

      return(false);

   end if;


   -- Check if the password differs from the previous password by at least

   -- 8 characters

   if old_password is not null then

      differ := ora_string_distance(old_password, password);

      if differ < 4 then

         ret := utl_lms.get_message(28211, 'RDBMS', 'ORA', lang, message);

         raise_application_error(-20000, utl_lms.format_message(message, 'four'));

      end if;


   --DAV4635 minimum_age

  select ptime into last_change from sys.user$ where name=username;

   if sysdate - last_change < minimum_age then

raise_application_error(-20010, 'Password changed too soon');

return(false);

   --DAV4635 minimum_age

    end if;

  end if;

   return(true);

end;

/

No comments:

Post a Comment