-- System trigger to restrict certain users to time of day
-- Copyright (c) 2004, Caleb.com

CREATE OR REPLACE TRIGGER cs_logon
AFTER LOGON ON DATABASE
DECLARE
   v_time    INTEGER;
BEGIN
   IF (ora_login_user IN ('MOE','LARRY','JOE')) THEN
      -- Put rational time based function here...
      SELECT to_char(sysdate,'ss') INTO v_time FROM dual;
      IF (v_time > 30) THEN
         INSERT INTO cs_log
            VALUES (sysdate, ora_login_user, 'Logon denied!');
         -- Raise exception to prevent logon (and rollback txn!)
         raise_application_error(-20003,'Logon denied!');
      END IF;
   END IF;
   -- Logon is successful if we get here
         INSERT INTO cs_log
            VALUES (sysdate, ora_login_user, 'Logon');
END;
/
