Re: Users functions library

Поиск
Список
Период
Сортировка
От Alejandro D. Burne
Тема Re: Users functions library
Дата
Msg-id 8398dc6d0807122109u6f574cees98fcc09d69db4d30@mail.gmail.com
обсуждение исходный текст
Ответ на Users functions library  ("Alejandro D. Burne" <alejandro.dburne@gmail.com>)
Ответы Re: Users functions library  ("Pavel Stehule" <pavel.stehule@gmail.com>)
Список pgsql-general
2008/7/12 Alejandro D. Burne <alejandro.dburne@gmail.com>:
> Hi, I need to write a function that gives me a password string, no
> just a numbers-characters string; something like people wrote in php,
> its based on determined syllables and numbers.
> I think it be useful to other people, is there a site where one can
> post it and share with other postgres users?
>
> Alejandro
>

Sorry, the function:

CREATE OR REPLACE FUNCTION gen_password(plenght smallint)
  RETURNS bpchar AS
$BODY$

DECLARE
lValid_Consonant bpchar DEFAULT 'BCDFGHJKMNPRSTV';
lValid_Vowel bpchar DEFAULT 'AEIOUY';
lValid_Numbers bpchar DEFAULT '23456789';

lConsonant_Length smallint DEFAULT char_length(lValid_Consonant);
lVowel_Length smallint DEFAULT char_length(lValid_Vowel);
lNumbers_Length smallint DEFAULT char_length(lValid_Numbers);

lPassword bpchar DEFAULT '';

BEGIN
LOOP
 IF ROUND(RANDOM()*3)<>1 THEN
  lPassword:=lPassword||SUBSTRING(lValid_Consonant FROM
(ROUND(RANDOM()*(lConsonant_Length-1))+1)::integer FOR 1)||
   SUBSTRING(lValid_Vowel FROM
(ROUND(RANDOM()*(lVowel_Length-1))+1)::integer FOR 1);
  IF ROUND(RANDOM()*2)<>1 THEN
   lPassword:=lPassword||SUBSTRING(lValid_Consonant FROM
(ROUND(RANDOM()*(lConsonant_Length-1))+1)::integer FOR 1);
  END IF;
 ELSE
  lPassword:=lPassword||SUBSTRING(lValid_Numbers FROM
(ROUND(RANDOM()*(lNumbers_Length-1))+1)::integer FOR 1);
 END IF;
 IF char_length(lPassword) >= plenght THEN
  EXIT;
 END IF;
END LOOP;

RETURN SUBSTRING(lPassword FROM 1 FOR plenght);
END;

$BODY$
  LANGUAGE 'plpgsql' VOLATILE;

В списке pgsql-general по дате отправления:

Предыдущее
От: "Alejandro D. Burne"
Дата:
Сообщение: Users functions library
Следующее
От: "Pavel Stehule"
Дата:
Сообщение: Re: Users functions library