Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 0E2BC9FBC5A for ; Tue, 5 Jun 2007 11:12:18 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 23116-04 for ; Tue, 5 Jun 2007 11:12:08 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wa-out-1112.google.com (wa-out-1112.google.com [209.85.146.182]) by postgresql.org (Postfix) with ESMTP id D0EB89FB78A for ; Tue, 5 Jun 2007 11:12:13 -0300 (ADT) Received: by wa-out-1112.google.com with SMTP id k40so2423709wah for ; Tue, 05 Jun 2007 07:12:11 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=IwJVS51iGeBWxYLljaanUo7SfFgQADaunOoELLBaKStJoFfiApUc5CysrZzzR74VSbxAxE42TS3hL3FiFnMRFyglOsnAM71M6aJVuHNok2YfnkSVFDF4Sbq2GjB0zt0tNn93id+uCufpJK3Yr8e8gdOLE4YUJxYaMa3mpn+9X3s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=qUqkB2ezdKwnaqggBnoFfXYZzQ6hzrgIDaJ9GfYqm2FwVxuu1ByCZxMeBXUJVWhKUnqesy/lT6gsFehnEBV64W70ssCuhSu/a2xChIhZFuPrDKpERWU0623uidQ+b2FCXF8lkJ7Z6fGOcIQl7odxC3D+SFpwaqHl0yKHRxgMiX8= Received: by 10.114.36.1 with SMTP id j1mr6035404waj.1181052731495; Tue, 05 Jun 2007 07:12:11 -0700 (PDT) Received: by 10.114.255.5 with HTTP; Tue, 5 Jun 2007 07:12:11 -0700 (PDT) Message-ID: Date: Tue, 5 Jun 2007 17:12:11 +0300 From: "Marko Kreen" To: "Tino Wildenhain" Subject: Re: Encrypted column Cc: "Ranieri Mazili" , pgsql-general@postgresql.org, pgsql-sql@postgresql.org In-Reply-To: <4665161F.9090009@wildenhain.de> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <46645B01.6070605@terra.com.br> <4665161F.9090009@wildenhain.de> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/397 X-Sequence-Number: 115220 On 6/5/07, Tino Wildenhain wrote: > Ranieri Mazili schrieb: > > Hello, > > > > I need to store users and passwords on a table and I want to store it > > encrypted, but I don't found documentation about it, how can I create a > > table with columns "user" and "password" with column "password" > > encrypted and how can I check if "user" and "password" are correct using > > a sql query ? > > Passwords are usually not encrypted but hashed instead. A common hash > function is available in postgres w/o any additional extension: > > md5() > > The rule is, if two hashes compare equal, then the original data must > be equal (yes, there are chances for collisions, but practically very > low. See also sha1 and friends in the pgcrypto contrib module) Both md5 and sha1 are bad for passwords, no salt and easy to bruteforce - due to the tiny amount of data in passwords. Proper ways is to use crypt() function from pgcrypto module. Due to historical accident is has bad name which hints at encryption, actually its only purpose is to hash passwords. Read more in pgcrypto doc. -- marko