Thread: Users functions library

Users functions library

From
"Alejandro D. Burne"
Date:
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

Re: Users functions library

From
"Alejandro D. Burne"
Date:
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;

Re: Users functions library

From
"Pavel Stehule"
Date:
Hello

safe it to pgfoundry http://pgfoundry.org/
regards
Pavel Stehule


2008/7/13 Alejandro D. Burne <alejandro.dburne@gmail.com>:
> 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;
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

Re: Users functions library

From
Karsten Hilbert
Date:
On Sat, Jul 12, 2008 at 11:14:27PM -0300, Alejandro D. Burne wrote:

> 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?

The wxPython wiki, section Cookbook, perhaps.

Karsten
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346

Re: Users functions library

From
"Alejandro D. Burne"
Date:
2008/7/13 Pavel Stehule <pavel.stehule@gmail.com>:
> Hello
>
> safe it to pgfoundry http://pgfoundry.org/
> regards
> Pavel Stehule
>
>

May be to much for including in pgfoundry, I think to build a place to
share code developed in postgres functions (plpgsql, plpython, etc)
and to categorize them. I can help to develop it, buy my natural
language is spanish and I'm uncomfortable writing in english.

Greetings, Alejandro



> 2008/7/13 Alejandro D. Burne <alejandro.dburne@gmail.com>:
>> 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;
>>
>> --
>> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-general
>>
>

Re: Users functions library

From
"Pavel Stehule"
Date:
2008/7/13 Alejandro D. Burne <alejandro.dburne@gmail.com>:
> 2008/7/13 Pavel Stehule <pavel.stehule@gmail.com>:
>> Hello
>>
>> safe it to pgfoundry http://pgfoundry.org/
>> regards
>> Pavel Stehule
>>
>>
>
> May be to much for including in pgfoundry, I think to build a place to
> share code developed in postgres functions (plpgsql, plpython, etc)
> and to categorize them. I can help to develop it, buy my natural
> language is spanish and I'm uncomfortable writing in english.
>
> Greetings, Alejandro
>

you can share code on http://www.pgsql.cz/index.php/PostgreSQL_SQL_Tricks

Regards
Pavel

>
>
>> 2008/7/13 Alejandro D. Burne <alejandro.dburne@gmail.com>:
>>> 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;
>>>
>>> --
>>> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
>>> To make changes to your subscription:
>>> http://www.postgresql.org/mailpref/pgsql-general
>>>
>>
>