Re: Username and Password authentication using pqxx library.

From: Klint Gore <kgore4(at)une(dot)edu(dot)au>
To: aravind chandu <avin_friends(at)yahoo(dot)com>
Cc: postgresql Forums <pgsql-general(at)postgresql(dot)org>
Subject: Re: Username and Password authentication using pqxx library.
Date: 2008-10-28 23:21:02
Message-ID: 49079E5E.4010607@une.edu.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

aravind chandu wrote:
> I am using pqxx API for postgresql.The following is the
> part of my code.The problem is in the query I am selecting the number
> of rows from the table since there is only one user name and password
> row it should return 1 and if there is no match then it should return
> 0.But here Even though I give wrong username or password its getting
> authenticated.please help me,what should I put in the "if ()"
> statement inorder to solve this issue .
>
> result R(T.exec("select count(*) from dbtable where
> username="+username+" and password="+password+""));
>
> if (R.empty())
> {
> throw logic_error("No tables found");
> *shm = '5';
> }
> else
> {
> cout<<"Authenticated";
> *shm='0';
> }
>
You don't want to test if the result is empty - you want to test if the
value returned is 0.

If you select the username and group by it, then you could test for the
empty result.

# select count(*) from users where username = 'hfkhsdf';
count
-------
0
(1 row)

# select username, count(*) from users where username = 'hfkhsdf' group
by 1;
username | count
----------+-------
(0 rows)

klint.

--
Klint Gore
Database Manager
Sheep CRC
A.G.B.U.
University of New England
Armidale NSW 2350

Ph: 02 6773 3789
Fax: 02 6773 3266
EMail: kgore4(at)une(dot)edu(dot)au

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-10-29 00:12:29 Re: UUID-OSSP Contrib Module Compilation Issue
Previous Message Christophe 2008-10-28 23:10:46 Re: postgresql and Mac OS X