Hi,
In my Apex Application I have two roles: USERS (Table: USERS_SP) and ADMINS (Table: ADMIN_VP).
And I want that the USERS and ADMINS can login via the same login-form/page where their just enter username and password.
And after they click login button the USER go to page (1) and if the ADMIN login it goes to page (2).
Is it possible? And how should I modify the code? My code do the Hash and match the parameters, but only for the table USERS_SP.
I am really new to all this stuff so I hope you excuse me for such questions.
CREATE TABLE USERS_SP
( "USERNAME" VARCHAR2(10) NOT NULL ENABLE,
"FORENAME" VARCHAR2(30) NOT NULL ENABLE,
"SURNAME" VARCHAR2(30) NOT NULL ENABLE,
"EMAIL" VARCHAR2(50) NOT NULL ENABLE,
"PASSWORD_HASH" RAW(16),
CONSTRAINT "USERS_SP_PK" PRIMARY KEY ("USERNAME") USING INDEX ENABLE,
)
/
CREATE TABLE ADMIN_VP
( "ADMINNAME" VARCHAR2(30) NOT NULL ENABLE,
"EMAIL" VARCHAR2(50) NOT NULL ENABLE,
"PASSWORD_HASH" RAW(16),
CONSTRAINT "ADMIN_VP_PK" PRIMARY KEY ("ADMINNAME") USING INDEX ENABLE,
)
/
create or replace package pkg_auth as
function authenticate(p_username in varchar2, p_password in varchar2)
return boolean;
end;
create or replace package body pkg_auth as
-- wrapper function to compute the MD5 hash
function md5hash (p_input in varchar2) return varchar2 is
begin
return dbms_crypto.hash(utl_raw.cast_to_raw(p_input),2);
end md5hash;
function authenticate(p_username in varchar2, p_password in varchar2)
return boolean is
v_result integer := 0;
v_hash varchar2(32);
begin
v_hash := md5hash(p_username || p_password);
select 1
into v_result
from users_sp
where upper(username) = upper(p_username)
and password_hash = v_hash;
return(v_result = 1);
exception
when no_data_found then
return false;
end authenticate;
end;
end authenticate;
end;