如何在Oracle Apex应用程序中使两个身份验证方案/功能正常工作。

huangapple go评论54阅读模式
英文:

How to have 2 authentication schemes / functions working in an Oracle Apex app

问题

我有一个应用程序,其中有两个用户表,一个是员工表,一个是客户表,如下面的模型所示:

如何在Oracle Apex应用程序中使两个身份验证方案/功能正常工作。

因此,我有一个名为SECAPP的包,其中包含一个hash_pwd函数和两个authenticate函数。

CREATE OR REPLACE PACKAGE SECAPP AS
-->>--------------------------------------------------------------------
 FUNCTION hash_pwd (
  p_username IN VARCHAR2,
  p_password IN VARCHAR2
 ) RETURN VARCHAR2;
--<<--------------------------------------------------------------------

-->>--------------------------------------------------------------------
 FUNCTION authenticate_clients(
  p_username IN VARCHAR2,
  p_password IN VARCHAR2
 ) RETURN BOOLEAN;
--<<--------------------------------------------------------------------

-->>--------------------------------------------------------------------
 FUNCTION authenticate_employes(
  p_username IN VARCHAR2,
  p_password IN VARCHAR2
 ) RETURN BOOLEAN;
--<<--------------------------------------------------------------------
END SECAPP;
/

CREATE OR REPLACE PACKAGE BODY SECAPP IS

-->>--------------------------------------------------------------------
FUNCTION hash_pwd(p_username IN VARCHAR2, p_password IN VARCHAR2)
	RETURN VARCHAR2
    IS
	l_password VARCHAR2(4000);
	l_salt VARCHAR2(4000) := 'mysalt';
BEGIN
	l_password := utl_raw.cast_to_raw(dbms_obfuscation_toolkit.md5
	(input_string => p_password || SUBSTR(l_salt,10,13) || p_username || SUBSTR(l_salt, 4, 10)));
	RETURN l_password;
END hash_pwd;
--<<--------------------------------------------------------------------

-->>--------------------------------------------------------------------
FUNCTION authenticate_clients (p_username IN VARCHAR2, p_password in VARCHAR2)
RETURN BOOLEAN
as
L_COUNT number(1) := 0;
begin

SELECT COUNT(*) INTO l_count FROM CLIENTS
where upper(email) = upper(p_username)
AND pwd = hash_pwd(p_username, p_password);

RETURN (l_count > 0);
END authenticate_clients;
--<<--------------------------------------------------------------------

-->>--------------------------------------------------------------------
FUNCTION authenticate_employes (p_username IN VARCHAR2, p_password IN VARCHAR2)
RETURN BOOLEAN
AS 
l_count NUMBER(1) := 0;
BEGIN
SELECT COUNT(*) INTO l_count FROM EMPLOYES
WHERE UPPER(email) = UPPER(p_username)
AND pwd = hash_pwd(p_username, p_password);

RETURN (l_count > 0);
END authenticate_employes;
--<<--------------------------------------------------------------------
END SECAPP;
/

我想要有两个登录门户:

  1. Apex的原始客户端登录页面。
  2. 另外一个员工登录页面,我可以基于原始页面进行复制。

在登录页面的处理过程中,有这个函数 apex_authentication.login(p_username => :P9999_USERNAME, p_password => :P000_PASSSWORD);

我尝试将它更改为 secapp.authenticate_employees(p_username => ....),但似乎不起作用,只有当我保留原始的Apex函数并将我的 authenticate_employees 设置为当前方案时才能正常工作。

我如何实现两个身份验证函数?

注:我不想合并我的员工和客户表,因为它们包含不同的数据。

如果需要更多信息,请告诉我,因为我已经很久没有在Stack Overflow上发帖了。

提前感谢您的帮助。

Thomas

更新

感谢Koen Lostrie提供的解决方案,下面是我的函数,它检查PAGE_ID并执行两个身份验证函数中的一个代码:

FUNCTION authenticate_wrapper(p_username IN VARCHAR2, p_password in VARCHAR2)
RETURN BOOLEAN
AS
l_count NUMBER(1) := 0;
l_app_page_id VARCHAR2(5) := NV('APP_PAGE_ID');
l_result BOOLEAN := false;
BEGIN

IF (l_app_page_id = '9998') THEN 
l_result := authenticate_clients(p_username => p_username, p_password => p_password);
END IF;
IF (l_app_page_id = '9999') THEN
l_result := authenticate_employes(p_username => p_username, p_password => p_password);
END IF;
RETURN l_result;
END authenticate_wrapper;

或者,将两个函数的代码直接放入其中:

FUNCTION authenticate_wrapper(p_username IN VARCHAR2, p_password in VARCHAR2)
RETURN BOOLEAN
AS
l_count NUMBER(1) := 0;
l_app_page_id VARCHAR2(5) := NV('APP_PAGE_ID');
BEGIN

IF (l_app_page_id = '9998') THEN 
SELECT COUNT(*) INTO l_count FROM clients
where upper(email) = upper(p_username)
AND pwd = hash_pwd(p_username, p_password);

RETURN (l_count > 0);
END IF;
IF (l_app_page_id = '9999') THEN
SELECT COUNT(*) INTO l_count FROM EMPLOYES
WHERE UPPER(email) = UPPER(p_username)
AND pwd = hash_pwd(p_username, p_password);

RETURN (l_count > 0);
END IF;
END authenticate_wrapper;
英文:

I have an app where I have 2 tables for users, one for the employees, one for the clients, as you can see on the model below

如何在Oracle Apex应用程序中使两个身份验证方案/功能正常工作。

So, I have a package (SECAPP) with a hash_pwd function, and 2 authenticate function.

CREATE OR REPLACE PACKAGE SECAPP AS
-->>--------------------------------------------------------------------
FUNCTION hash_pwd (
p_username IN VARCHAR2,
p_password IN VARCHAR2
) RETURN VARCHAR2;
--<<--------------------------------------------------------------------
-->>--------------------------------------------------------------------
FUNCTION authenticate_clients(
p_username IN VARCHAR2,
p_password IN VARCHAR2
) RETURN BOOLEAN;
--<<--------------------------------------------------------------------
-->>--------------------------------------------------------------------
FUNCTION authenticate_employes(
p_username IN VARCHAR2,
p_password IN VARCHAR2
) RETURN BOOLEAN;
--<<--------------------------------------------------------------------
END SECAPP;
/
CREATE OR REPLACE PACKAGE BODY SECAPP IS
-->>--------------------------------------------------------------------
FUNCTION hash_pwd(p_username IN VARCHAR2, p_password IN VARCHAR2)
RETURN VARCHAR2
IS
l_password VARCHAR2(4000);
l_salt VARCHAR2(4000) := 'mysalt';
BEGIN
l_password := utl_raw.cast_to_raw(dbms_obfuscation_toolkit.md5
(input_string => p_password || SUBSTR(l_salt,10,13) || p_username || SUBSTR(l_salt, 4, 10)));
RETURN l_password;
END hash_pwd;
--<<--------------------------------------------------------------------
-->>--------------------------------------------------------------------
FUNCTION authenticate_clients (p_username IN VARCHAR2, p_password in VARCHAR2)
RETURN BOOLEAN
as
L_COUNT number(1) := 0;
begin
SELECT COUNT(*) INTO l_count FROM CLIENTS
where upper(email) = upper(p_username)
AND pwd = hash_pwd(p_username, p_password);
RETURN (l_count > 0);
END authenticate_clients;
--<<--------------------------------------------------------------------
-->>--------------------------------------------------------------------
FUNCTION authenticate_employes (p_username IN VARCHAR2, p_password IN VARCHAR2)
RETURN BOOLEAN
AS 
l_count NUMBER(1) := 0;
BEGIN
SELECT COUNT(*) INTO l_count FROM EMPLOYES
WHERE UPPER(email) = UPPER(p_username)
AND pwd = hash_pwd(p_username, p_password);
RETURN (l_count > 0);
END authenticate_employes;
--<<--------------------------------------------------------------------
END SECAPP;
/

I would like to have 2 logins portal

the original login page from Apex for the client, and an additional Employees login page that i could copy based on the original.

I've added the 2 authenticate functions in my authenticate schemes

In the Login Page process, there's this function apex_authentication.login(p_username => :P9999_USERNAME, p_password => :P000_PASSSWORD);

I tried changing it for secapp.authenticate_employees(p_username => ....). But it doesn't seems to work, it only works when I keep the original apex function and making my authenticate_employees the current scheme.

How could I achieve 2 authenticate function ?

NB : I dont want to merge my employees and clients table, since they have different data.

Let me know if you need more informations, as it has been a while since I posted on SO.

Thanks in advance

Thomas


UPDATE

Thanks Koen Lostrie for the solution, heres my function that check the PAGE_ID and execute either one code of the two authenticate functions

FUNCTION authenticate_wrapper(p_username IN VARCHAR2, p_password in VARCHAR2)
RETURN BOOLEAN
AS
l_count NUMBER(1) := 0;
l_app_page_id VARCHAR2(5) := NV('APP_PAGE_ID');
l_result BOOLEAN := false;
BEGIN
IF (l_app_page_id = '9998') THEN 
l_result := authenticate_clients(p_username => p_username, p_password => p_password);
END IF;
IF (l_app_page_id = '9999') THEN
l_result := authenticate_employes(p_username => p_username, p_password => p_password);
END IF;
RETURN l_result;
END authenticate_wrapper;

or.. with the code of the 2 functions directly in it :

FUNCTION authenticate_wrapper(p_username IN VARCHAR2, p_password in VARCHAR2)
RETURN BOOLEAN
AS
l_count NUMBER(1) := 0;
l_app_page_id VARCHAR2(5) := NV('APP_PAGE_ID');
BEGIN
IF (l_app_page_id = '9998') THEN 
SELECT COUNT(*) INTO l_count FROM clients
where upper(email) = upper(p_username)
AND pwd = hash_pwd(p_username, p_password);
RETURN (l_count > 0);
END IF;
IF (l_app_page_id = '9999') THEN
SELECT COUNT(*) INTO l_count FROM EMPLOYES
WHERE UPPER(email) = UPPER(p_username)
AND pwd = hash_pwd(p_username, p_password);
RETURN (l_count > 0);
END IF;
END authenticate_wrapper;

答案1

得分: 0

Here is the translated content:

更新

感谢Koen Lostrie提供的解决方案,这是检查PAGE_ID并执行两个身份验证函数之一的函数:

FUNCTION authenticate_wrapper(p_username IN VARCHAR2, p_password IN VARCHAR2)
RETURN BOOLEAN
AS
l_count NUMBER(1) := 0;
l_app_page_id VARCHAR2(5) := NV('APP_PAGE_ID');
l_result BOOLEAN := false;
BEGIN

IF (l_app_page_id = '9998') THEN 
l_result := authenticate_clients(p_username => p_username, p_password => p_password);
END IF;
IF (l_app_page_id = '9999') THEN
l_result := authenticate_employees(p_username => p_username, p_password => p_password);
END IF;
RETURN l_result;
END authenticate_wrapper;

或者,直接在其中包含了两个函数的代码:

FUNCTION authenticate_wrapper(p_username IN VARCHAR2, p_password IN VARCHAR2)
RETURN BOOLEAN
AS
l_count NUMBER(1) := 0;
l_app_page_id VARCHAR2(5) := NV('APP_PAGE_ID');
BEGIN

IF (l_app_page_id = '9998') THEN 
SELECT COUNT(*) INTO l_count FROM clients
where upper(email) = upper(p_username)
AND pwd = hash_pwd(p_username, p_password);

RETURN (l_count > 0);
END IF;
IF (l_app_page_id = '9999') THEN
SELECT COUNT(*) INTO l_count FROM EMPLOYEES
WHERE UPPER(email) = UPPER(p_username)
AND pwd = hash_pwd(p_username, p_password);

RETURN (l_count > 0);
END IF;
END authenticate_wrapper;
英文:

UPDATE

Thanks Koen Lostrie for the solution, heres my function that check the PAGE_ID and execute either one code of the two authenticate functions

FUNCTION authenticate_wrapper(p_username IN VARCHAR2, p_password in VARCHAR2)
RETURN BOOLEAN
AS
l_count NUMBER(1) := 0;
l_app_page_id VARCHAR2(5) := NV('APP_PAGE_ID');
l_result BOOLEAN := false;
BEGIN
IF (l_app_page_id = '9998') THEN 
l_result := authenticate_clients(p_username => p_username, p_password => p_password);
END IF;
IF (l_app_page_id = '9999') THEN
l_result := authenticate_employes(p_username => p_username, p_password => p_password);
END IF;
RETURN l_result;
END authenticate_wrapper;

or.. with the code of the 2 functions directly in it :

FUNCTION authenticate_wrapper(p_username IN VARCHAR2, p_password in VARCHAR2)
RETURN BOOLEAN
AS
l_count NUMBER(1) := 0;
l_app_page_id VARCHAR2(5) := NV('APP_PAGE_ID');
BEGIN
IF (l_app_page_id = '9998') THEN 
SELECT COUNT(*) INTO l_count FROM clients
where upper(email) = upper(p_username)
AND pwd = hash_pwd(p_username, p_password);
RETURN (l_count > 0);
END IF;
IF (l_app_page_id = '9999') THEN
SELECT COUNT(*) INTO l_count FROM EMPLOYES
WHERE UPPER(email) = UPPER(p_username)
AND pwd = hash_pwd(p_username, p_password);
RETURN (l_count > 0);
END IF;
END authenticate_wrapper;

huangapple
  • 本文由 发表于 2023年6月29日 15:19:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76578829.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定