Received: from iceberg.6tems.com ([212.31.53.129]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g02Ff3m64137 for ; Wed, 2 Jan 2002 10:41:09 -0500 (EST) (envelope-from teixi@6tems.com) Received: from satellite (studio.6tems.com [213.96.34.17]) (authenticated (0 bits)) by iceberg.6tems.com (8.11.1/8.11.1/IcebergMail 8.11.0-6) with ESMTP id g02FYR316270 for ; Wed, 2 Jan 2002 16:34:30 +0100 X-Authentication-Warning: iceberg.6tems.com: Host studio.6tems.com [213.96.34.17] claimed to be satellite Date: Wed, 2 Jan 2002 15:37:05 +0100 From: Jaume Teixi To: pgsql-php@postgresql.org Subject: Re: WWW-Authentication and Postgresql [sample_code_inline] Message-Id: <20020102153705.1cb660de.teixi@6tems.com> In-Reply-To: References: <1009443251.14763.6.camel@kant.mcmillan.net.nz> X-Mailer: Sylpheed version 0.6.6 (GTK+ 1.2.10; powerpc-debian-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Archive-Number: 200201/2 X-Sequence-Number: 809 hi, here is how I handle a basic authentication form against postgresql put your dbname, user and passwd on $dbcredentials put your table on $dbtable and the user and passwd cols on $dbid and $dbpw see you, teixi. ps: so in my case the testdb contains a test_table where the user column is called test_login and the passwd column is test_passw \n"; echo "Login:
\n"; echo "Password:
\n\n"; echo "\n"; echo "\n"; echo "\n"; if($inside=='-1') { echo "

Invalid credentials.

"; } exit; } if( $authy_user=='' || $authy_pw=='' ) { $inside = 0; authy($inside); } else { $conn = pg_pconnect($dbcredentials) or die ('DB Unavailable'); $login = strtolower($authy_user); $data = "SELECT * FROM $dbtable WHERE $dbid='$login' AND $dbpw='$authy_pw'"; $query = pg_exec($conn, $data) or die ('Unable to execute query'); if (!pg_numrows($query)) { $inside = -1; authy($inside); } else { $inside = 1; pg_close($conn); } } echo "

You're Inside :-)


"; ?> On Thu, 27 Dec 2001 10:51:03 -0500 (EST) Vince Vielhaber was typing: > On 27 Dec 2001, Andrew McMillan wrote: > > > > > > > A couple of quick gotchas. 1) make sure you filter out all unwanted > > > characters so someone can't execute sql calls inside of a username or > > > password. 2) On failure make sure you send a 401 to the browser just > > > like you do initially when asking for the password to clear out the old > > > one - you can also use this to handle logouts. > > > > > I think that what Vince was getting at particularly, in replying to my > > post suggesting not to use database-level users, was that if you are not > > using database level users then there is a greater risk of this being a > > problem. I would tend to dispute that - I think this is a risk > > _anytime_. Paranoia rules. > > Nope, all I was saying was to filter out all input from the browser. > you don't want any apostrophes, or probably anything other than a-z, > A-Z, 0-9. and to use the 401 to clear out failures. > > Vince.