agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Jan Otto <asche@me.com>
To: Gary Stainburn <gary.stainburn@ringways.co.uk>
Cc: pgsql-sql@postgresql.org
Subject: Re: simple "select / if found" isn't
Date: Fri, 16 Dec 2016 12:34:48 +0100
Message-ID: <C9BFAD75-EB0B-4107-A6D9-31ED34D7AF6D@me.com> (raw)
In-Reply-To: <201612161102.37559.gary.stainburn@ringways.co.uk>
References: <201612161102.37559.gary.stainburn@ringways.co.uk>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>
hi gary,
> On 16 Dec 2016, at 12:02, Gary Stainburn <gary.stainburn@ringways.co.uk> wrote:
>
> I'm creating a simple function that must have been done millions of times
> before, but I can't get it to work. In this case, I'm checking a user ID and
> password against previously used passwords:
>
> All I want to do is return 'found' based on the select but I can't get it to
> work.
>
> If I run
>
> select 1 from user_previous_passwords
> where u_id=25 and
> crypt('MyPaSSword',u_previous_password) = u_previous_password;
>
> then it returns the matching row(s)
>
> If I run my function
>
> create or replace function check_previous_passwords (ID int4, PASS varchar)
> returns boolean as $$
> DECLARE
> UID int4;
> BEGIN
> return exists(select 1 from user_previous_passwords
> where u_id=ID and crypt(PASS,u_previous_password) = PASS);
return exists(select 1 from user_previous_passwords
where u_id=ID and crypt(PASS,u_previous_password) = u_previous_password);
> END;
> $$ LANGUAGE plpgsql;
regards, jan
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
view thread (6+ messages) latest in thread
Message-ID: <C9BFAD75-EB0B-4107-A6D9-31ED34D7AF6D@me.com>
Permalink: ../C9BFAD75-EB0B-4107-A6D9-31ED34D7AF6D@me.com/
Also on: postgresql.org/message-id/C9BFAD75-EB0B-4107-A6D9-31ED34D7AF6D@me.com
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: asche@me.com, gary.stainburn@ringways.co.uk
Subject: Re: simple "select / if found" isn't
In-Reply-To: <C9BFAD75-EB0B-4107-A6D9-31ED34D7AF6D@me.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox