Re: [GENERAL] encrypted field

From: Henrique Pantarotto <scanner(at)cepa(dot)com(dot)br>
To: Gregoire Pichon <grpichon(at)yahoo(dot)com>, pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] encrypted field
Date: 1999-09-17 12:03:58
Message-ID: 99091709221907.09551@scanner.cepa.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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 (scanner(at)cepa(dot)com(dot)br)
* 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
scanner(at)cepa(dot)com(dot)br

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: scanner(at)cepa(dot)com(dot)br
Tel: (011) 5506-8477
Cel: (011) 9706-3444
LINUX FRIEND

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sebestyen Zoltan 1999-09-17 13:41:14 oid_index size problem
Previous Message Gregoire Pichon 1999-09-17 07:54:41 encrypted field