Hi Gang,
I am trying to write a series of functions in PL/PGSQL to handle among
other things user login. The way the application is written right now,
when the user provides a username/password pair, the program retrieves
the user_name, password, access_flag, etc... If the user/pass combo
supplied matches the one on the table, then the login process goes
through. If on the other hand only the user name is valid, a message
is displayed to let the user know the login failed as well as
initializing a login attempt counter (invisible to the user). If booth
user/pass are invalid, then a simple error messahe is displayed. I was
thinking it would make more sense to write a function to return only
the columns that would be used in any instance, rather than returning
everything and having the program do the checking--to be honest, I am
not sure which way is more cost effective. Anyways, here is the
pseudo-code for one of these functions...

CREATE OR REPLACE FUNCTION userlogin(username varchar, password
varchar) RETURNS TYPE_TYPE AS $RETURN_TYPE$
  DECLARE
    name TYPE_TYPE;
  BEGIN
  SELECT INTO name (tusername, tpassword, taccessflag) FROM table_name
WHERE (tusername=username);
  IF ((name.tusername == username) && (name.tpassword == password)) THEN
    RETURN name;
  ELSE IF ((name.tusername == username) && (name.tpassword != password)) THEN
    RETURN (name.tusername, name.taccessflag);
  ELSE
    RETURN NULL;
  END IF;
  END;
$RETURN_TYPE$ language plpgsql;

--
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
-------------------Cirez Communications, inc.----------------
----------------------Juan Alberto Cirez---------------------
-----------------------Senior Consultant---------------------
[EMAIL PROTECTED]
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
          Sunny and Beautiful Vancouver, Canada.
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

_______________________________________________
clug-talk mailing list
[email protected]
http://clug.ca/mailman/listinfo/clug-talk_clug.ca
Mailing List Guidelines (http://clug.ca/ml_guidelines.php)
**Please remove these lines when replying

Reply via email to