-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Gorka wrote:
> ¿Hay alguna manera en postgres de crear una función que genere passwords
> aleatorias?
> 

Hola

Te mando esta funcion que puedes utilizar para generar claves
aleatorias. El parametro aleatorio lo define la funcion random().

- ------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION generate_password(integer) RETURNS TEXT AS $$
DECLARE
  len ALIAS FOR $1;
  cnt INTEGER;
  password TEXT :='';

  characters_not_included TEXT := E''',-./:;<>@^_`\\';
 BEGIN

  FOR cnt IN 1..len LOOP
    password := password || chr(round((random()*87)+35)::integer);
  END LOOP;

  password :=
translate(password,characters_not_included,substr(md5(random()::text),round((random()*(32-char_length(characters_not_included))))::integer,char_length(characters_not_included)));

RETURN password;

END;
$$ LANGUAGE plpgsql;
- ------------------------------------------------------------------------

Ejemplo:

SELECT generate_password(8);
 generate_password
- -------------------
 r58R1N=Z
(1 row)

- --
 Rafael Martinez, <r.m.guerr...@usit.uio.no>
 Center for Information Technology Services
 University of Oslo, Norway

 PGP Public Key: http://folk.uio.no/rafael/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQFKzfEBBhuKQurGihQRAjqQAJwPHPddZ2o94SFMM/R1tgYBQ1VsYwCeLqoG
pGzGrCMQf6elmOgoQ+sKH4U=
=c8rf
-----END PGP SIGNATURE-----
--
TIP 6: ¿Has buscado en los archivos de nuestra lista de correo?
               http://archives.postgresql.org/pgsql-es-ayuda

Responder a