Re: PL/SQL password generator

From: Thomas Kyte <tkyte_at_us.oracle.com>
Date: Tue, 12 Oct 1999 10:19:08 -0400
Message-ID: <d0IDOM8owjtDUyGmG8bYzyng9rF7_at_4ax.com>


A copy of this was sent to "Peter" <Pjotr_at_dolfijn.nl> (if that email address didn't require changing) On Tue, 12 Oct 1999 12:35:45 +0200, you wrote:

>Howdy,
>
>Does anyone have a pl/sql pasword generator that can be used as a function.
>
>Peter
>p.c.de.wolff_at_pve.agro.nl
>

Here is one I've used:

function generate_password(in_userid in varchar2 ) return varchar2 is

  j      number := 0;
  k      number;

  str varchar2(30);
  result varchar2(30);
begin

   if in_userid is null then

       return null;
   end if;

   str := substr(in_userid, 1, 4) || to_char(sysdate, 'SSSS');

   for i in 1..least(length(str), 8)
   loop

      j := mod(j + ascii(substr(str, i, 1)), 256);
      k := mod(bitand(j,ascii(substr(str, i, 1))), 74)+48;
      if k between 58 and 64 then
         k := k + 7;
      elsif k between 91 and 96 then
         k := k + 6;
      end if;
      result := result || chr(k);

    end loop;
    result := replace( result, '1', '2' );
    result := replace( result, 'l', 'L' );
    result := replace( result, '0', '9' );
    result := replace( result, 'O', 'P' );
    result := 'A' || substr( result, 2);
    return result;
end generate_password;

It makes sure the generated password does not contain nasty characters like 1, l, O, 0 as they (in courier anyway) look the same...

-- 
See http://osi.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'...
Current article is "Part I of V, Autonomous Transactions" updated June 21'st
 
Thomas Kyte                   tkyte_at_us.oracle.com
Oracle Service Industries     Reston, VA   USA

Opinions are mine and do not necessarily reflect those of Oracle Corporation
Received on Tue Oct 12 1999 - 16:19:08 CEST

Original text of this message