Professional Documents
Culture Documents
org/web/fe/default/en/document/1349977/custom-authenticationin-oracle-apex
1- Introduction
This document is based on:
3- SQL Script
To begin this example, you need to run Script to create table to store user and create
package.
Create USER_ACCOUNT table:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
table USER_ACCOUNT
constraint USER_ACCOUNT_PK primary key (USER_NAME) ;
table USER_ACCOUNT
constraint USER_ACCOUNT_UK unique (EMAIL) ;
20
21
22
23
24
25
26
27
28
29
30
PKG_SECURITY
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Apex_Util.Set_Session_State('LOGIN_MESSAGE'
,'Please enter Username and
password.');
Return False;
End If;
---Begin
Select u.Active
,u.Password
,u.Email
Into v_Active
,v_Password
,v_Email
From User_Account u
34
Where u.User_Name = p_User_Name;
Exception
35
When No_Data_Found Then
36
37
-- Write to Session, User not found.
38
Apex_Util.Set_Session_State('LOGIN_MESSAGE'
39
,'User not found');
Return False;
40
End;
41
If v_Password <> p_Password Then
42
43
-- Write to Session, Password incorrect.
44
Apex_Util.Set_Session_State('LOGIN_MESSAGE'
45
,'Password incorrect');
Return False;
46
End If;
47
If v_Active <> 'Y' Then
48
Apex_Util.Set_Session_State('LOGIN_MESSAGE'
49
,'User locked, please contact admin');
50
Return False;
End If;
51
--52
-- Write user information to Session.
53
-54
Apex_Util.Set_Session_State('SESSION_USER_NAME'
,p_User_Name);
55
Apex_Util.Set_Session_State('SESSION_EMAIL'
56
,v_Email);
57
--58
--59
Return True;
End;
60
61
-------------------------------------62
Procedure Process_Login(p_User_Name Varchar2
63
,p_Password Varchar2
64
,p_App_Id
Number) As
65
v_Result Boolean := False;
Begin
66
v_Result := Authenticate_User(p_User_Name
67
,p_Password);
68
If v_Result = True Then
69
-- Redirect to Page 1 (Home Page).
Wwv_Flow_Custom_Auth_Std.Post_Login(p_User_Name -- p_User_Name
70
,p_Password -- p_Password
71
,v('APP_SESSION') -72 p_Session_Id
73
,p_App_Id || ':1' -74 p_Flow_page
);
75
Else
76
-- Login Failure, redirect to page 101 (Login Page).
77
Owa_Util.Redirect_Url('f?p=&APP_ID.:101:&SESSION.');
78
End If;
79
End;
80
81
82
83
84
85
86 End Pkg_Security;
87 /
88
89
90
91
92
1 Apex_Util.Set_Session_State('LOGIN_MESSAGE'
2
SESSION_USER_NAME
SESSION_EMAIL
5- Custom Authentication
Open LOGIN page in APEX Page designer:
Next you have to modify code handling process when the user clicks the Submit button.
PL/SQL Code:
1 Pkg_Security.Process_Login(:P101_USERNAME,
:P101_PASSWORD,
2
:APP_ID);
3