Hello Greg,
I've created a stupid little C trigger that is kinda like MySQL's "encrypt"
function. I use it to store passwords in the UNIX crypt format.
Here's the encrypt.c:
--------------------------------------------------------
/*
*
* Henrique Pantarotto ([EMAIL PROTECTED])
* Funcao para encriptar senhas (Function to encrypt passwords)
* September 1999
*
* Create trigger like this:
* create function encrypt(text) returns text as
* '/usr/local/pgsql/hpmail/encrypt.so' language 'c';
*
*/
#include <stdio.h>
#include <strings.h>
#include <unistd.h>
#include <postgres.h>
#include <utils/builtins.h>
text *encrypt (text *user);
text *encrypt(text *user)
{
char *password;
password = crypt(textout(user), "HP");
return textin(password);
}
----------------------------------------------------------
Compile using something like this:
1: gcc -I/down/postgresql-6.5.1/src/include -I$/down/postgresql-6.5.1/src/backend -O2
-Wall -Wmissing-prototypes -fpic -I/down/postgresql-6.5.1/src/include -c -o encrypt.o
encrypt.c
2: gcc -shared -o encrypt.so encrypt.o
(my postgres sources are in /down/postgresql-6.5.1, you'll need to change this
path)
And last, you create the trigger in PostgreSQL using this:
create function encrypt(text) returns text as '/usr/local/pgsql/encrypt.so' language
'c';
If everything is okay, you'll probably have: select encrypt('secret') working
and showing:
encrypt
------------
HPK1Jt2NX21G.
(1 row)
blabla=>
PS: Note that all crypted passwords are created with salt "HP" (my name
initials..) You can change that, or if you know C, you can do in a way that it
will pick two random characters (the way it should really be).
I'm no experience C programmer, nor an experienced PostgreSQL user, so maybe
there's a smarter way to do this same thing.. (there might be even a built in
function that I don't know).
Good luck and regards from Brazil,
Henrique Pantarotto
Sao Paulo, SP - Brasil
[EMAIL PROTECTED]
On sex, 17 set 1999, Gregoire Pichon wrote:
> Hello,
>
> How can I crypt the field of a table?
> This field will contain secret data, I need therefore
> to crypt this field to avoid those data to be stored
> on the disk unprotected.
>
> Where can I found documentation on this topic?
>
> Thanks
> Greg
>
> __________________________________________________
> Do You Yahoo!?
> Bid and sell for free at http://auctions.yahoo.com
>
> ************
--
Henrique Pantarotto
CEPAnet Internet Provider
webmaster / analista de sistemas
Email: [EMAIL PROTECTED]
Tel: (011) 5506-8477
Cel: (011) 9706-3444
LINUX FRIEND
************