AFTER ALTER ON DATABASE gives the old password value in Oracle - oracle

I am writing a trigger to fetch the 'password' value when 'sys.users$' table gets updated.
CREATE OR REPLACE
TRIGGER Sys_User_Nm_Trg AFTER ALTER ON DATABASE
WHEN (ora_dict_obj_type = 'USER')
DECLARE
CURSOR get_pw IS
SELECT password
FROM sys.user$
WHERE name = ora_dict_obj_name;
user_pw_ VARCHAR2(100);
BEGIN
IF (ora_dict_obj_name != 'SYS' AND ora_dict_obj_name != 'SYSTEM') THEN
IF (ora_des_encrypted_password IS NOT NULL) THEN
OPEN get_pw;
FETCH get_pw INTO user_pw_;
CLOSE get_pw;
END IF;
END IF;
END;
/
But this cursor gives the old 'password' not the changed 'password' value. But if I run
SELECT password
FROM sys.user$
WHERE name = ora_dict_obj_name;
in a separate transaction it gives the correct changed value. Is there something that I should change in the trigger to fetch the updated value for the password?

Related

SQL Fiddle - Oracle Stored Procedure not updating rows

I am trying to learn Oracle stored procedures and I cannot make them run properly on SQL Fiddle or DBfiddle. I don't have access to an installed Oracle database.
Here is my code from http://sqlfiddle.com/#!4/e53857/5
CREATE TABLE user_1 (password varchar(10))
/
create procedure updateUsers
( new_p in varchar2)
as
begin
SAVEPOINT before;
update user_1 set password = 'in proc';
dbms_output.put_line(SQL%RowCount);
commit;
EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('Error: ' || SQLCODE || ' - ' || SQLERRM);
end;
/
and the query pane
insert into user_1 values ('initial');
select password from user_1;
update user_1 set password = 'from query';
SELECT password from user_1;
exec (updateUsers );
select password from user_1;
When I look at the last output below the update in the query pane has worked, the stored procedure hasn't changed anything, the value of password is still from query and there is no error message.
The line ending in the left pane is / and ; in the right pane.
I would appreciate any help and pointers.
If another online tool is easier to use for Oracle than SQL fiddle I'm open to suggestions.
I've found the solution!
schema pane, line ending / both panes
CREATE TABLE user_1 (password varchar(10))
/
create procedure updateUsers
( new_p in varchar2)
as
begin
SAVEPOINT before;
update user_1 set password = new_p;
dbms_output.put_line(SQL%RowCount);
commit;
EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('Error: ' || SQLCODE || ' - ' || SQLERRM);
end;
/
query pane
insert into user_1 values ('initial')/
select password from user_1/
update user_1 set password = 'from query'/
SELECT password from user_1/
begin
updateUsers('new_pass') ;
end;
/
select password from user_1/
output
PASSWORD
initial
PASSWORD
from query
PASSWORD
new_pass
see also extension
http://sqlfiddle.com/#!4/b942cc/3

Redirect if password is expired in Oracle Apex

I am using Database Account authentication in an app. I want to automatically redirect user to Reset Password Application (it is separate app) if password is expired.
I have created Before Header process which is following
begin
if instr(owa_util.get_cgi_env('QUERY_STRING'),'&notification_msg=Password%20Expired/') > 0 then
apex_application.g_unrecoverable_error := true;
owa_util.redirect_url('http://www.oracle.com');
end if;
end;
The issue is that notification_msg is not in plain text. It is like below
&notification_msg=UGFzc3dvcmQgRXhwaXJlZDxkaXYga..#moregibberish
Due to this QUERY_STRING is not matched, hence can't redirect. Any suggestion on how could I identify if Password is expired of if I could encode 'Password Expired' (plain notification text) into same as &notification_msg value through code?
Using Apex 21.2 and Database 12c
Resolved through different approach
Created After Header Process in Pre rendering with following code
declare
v_count number;
begin
select count(1)
into v_count
from apex_workspace_activity_log
where application_id = :APP_ID
and error_on_component_type = 'AUTHENTICATION'
and error_on_component_name = 'DATABASE ACCOUNT'
and apex_session_id = :APP_SESSION
and view_timestamp between systimestamp - interval '2' second and systimestamp + interval '2' second
and upper(error_message) like upper('Password Expired (user=' || :P101_USERNAME || ')');
if v_count > 0 then
apex_application.g_unrecoverable_error := true;
apex_util.redirect_url(p_url => 'f?p=9999999:1:'||:APP_SESSION);
end if;
end;

DBMS_OUTPUT.PUT_LINE not showing message to user

I am trying to create a trigger that would check for a null value in column namesdreservation_status from my table passenger and set it to a default value if it's null and show the user a message of it being set to default.
The trigger is created and works fine for setting the default but no message is shown to the user.
create or replace trigger mytrigger
before insert or update on passenger
for each row
when (new.reservation_status IS NULL)
begin
IF :new.reservation_status IS NULL THEN
:new.reservation_status := 'not reserved';
dbms_output.put_line('reservation status invalid, set to default');
end IF;
end mytrigger
/
The value gets changed to 'not reserved' if its null but the message 'reservation status invalid, set to default' isn't displayed. Help.
Trigger's don't do anything until they're actually triggered - in this case, on an INSERT.
clear screen
set serveroutput on
drop table passenger;
create table passenger (id integer, reservation_status varchar2(25));
create or replace trigger mytrigger
before insert or update on passenger
for each row
when (new.reservation_status IS NULL)
begin
IF :new.reservation_status IS NULL THEN
:new.reservation_status := 'not reserved';
dbms_output.put_line('reservation status invalid, set to default');
end IF;
end mytrigger;
/
insert into passenger values (1, null);
commit;
If I run this in SQLPlus, SQLcl, or SQL Developer -
And if we check the table, you can see our trigger, 'worked.'

Oracle 11g manual user authentication

I need help to create a manual user authentication in Oracle DB 11g.
A separate table is there which contains authorized user names. If the user is not in the table, he will get disconnected with a message stating something like 'you are not authorized' or something.
This the function I created to get return code based on username presence in ref table:
create or replace function user_check return integer is
user_name varchar2(10);
cursor usr is select * from user_ref;
begin
select USERNAME into user_name
from v$session where audsid = sys_context('userenv','sessionid');
for u in usr loop
if u.user_name = user_name then
return 1;
goto out_of_loop;
end if;
end loop;
return 0;
<<out_of_loop>>
null;
end;
/
I am trying to create a trigger as:
create or replace trigger user_verify_trg after logon on database
declare
sid varchar2(10);
serial varchar2(10);
q varchar2(100);
begin
if(gs.user_check = 1) then
select SID, serial# into sid,serial
from v$session where audsid = sys_context('userenv','sessionid');
q := 'alter system kill session '||sid||','||serial;
execute immediate q;
end if;
end;
/
But it's not working. Please help.

Date today from a Display Item insert to database

I made a table that has a column Date_Created in it. And in my form I put a display item above having a formula of sysdate so that each time the form runs and insert new data, the date will always e updated but when I looked up into the database, Date_Created is blank!
What causes this problem? tnx
screen shots:
http://static.tumblr.com/ezdv8nl/YcUmu2vcc/untitled_1.jpg
My code for the submit button:
DECLARE
adminPass VarChar(20);
alert Number;
BEGIN
IF :USERS.PASS != :USERS.PASS2 OR :USERS.PASS IS NULL THEN
MESSAGE('Passwords did not match');
GO_ITEM('PASS2');
ELSIF :USERS.ACCESS_LEVEL = 'admin' THEN
SELECT password
INTO adminPass
FROM admin_pass_history
WHERE id = (SELECT MAX(id) FROM admin_pass_history);
IF :USERS.ADMIN_PASS IS NULL THEN
MESSAGE('Please enter the Administrator Password');
ELSIF :USERS.ADMIN_PASS != adminPass THEN
MESSAGE('Administrator Password did not match');
GO_ITEM('ADMIN_PASS');
ELSE
COMMIT;
alert:= show_alert('USER_CREATED');
IF alert = alert_button1 THEN
OPEN_FORM('C:\Documents and Settings\Richzer Cruz\Desktop\LOGIN.fmx');
END IF;
END IF;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
MESSAGE('Administrator Password did not match');
GO_ITEM('ADMIN_PASS');
END;
The first thing is to make sure that your display item is a database item property set to Yes.
From what I remember items with formulas are not saved to database. Remove formula and use WHEN-CREATE_RECORD trigger.

Resources