From: | Jeff Ross <jross(at)wykids(dot)org> |
---|---|
To: | Robert Fitzpatrick <lists(at)webtent(dot)net> |
Cc: | PostgreSQL <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Generate random password |
Date: | 2007-06-07 19:25:25 |
Message-ID: | 46685BBC.8070201@wykids.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Robert Fitzpatrick wrote:
> Can anyone suggest how one might be able to do this? I want to be able
> to generate an 8 character random password for users in their password
> field. Perhaps through the default setting of the field or a trigger
> function. I found the following, but is there anything that can be used
> on both Windows and *nix or can this be used on Windows somehow?
>
> http://pgfoundry.org/forum/forum.php?forum_id=994
>
Here's a simple function I've used so I can do it in the database.
Written with help from this very list ;-)
CREATE OR REPLACE FUNCTION gen_password() RETURNS text AS $$
DECLARE
password text;
chars text;
BEGIN
password := '';
chars :=
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
FOR i IN 1..8 LOOP
password := password || SUBSTRING(chars,
ceil(random()*LENGTH(chars))::integer, 1);
END LOOP;
return password;
END;
$$
LANGUAGE plpgsql;
Then you can do stuff like:
update people set pp_password = gen_password() where pp_password is null;
Jeff
From | Date | Subject | |
---|---|---|---|
Next Message | Magnus Hagander | 2007-06-07 19:25:49 | Re: Generate random password |
Previous Message | Michael Glaesemann | 2007-06-07 19:22:44 | Re: subtract a day from the NOW function |