APEX 通過資料庫中使用者資訊驗證登陸
1. Custom Authentication in Oracle APEX
參考:https://o7planning.org/en/10443/custom-authentication-in-oracle-apex
1.1. Introduction
This document is based on:
· Oracle APEX 5.0
· Oracle APEX 5.1.4 測試可用
1.2. Default authentication of APEX
APEX預設登入頁是101,預設驗證方式APEX使用者驗證。本文主要測試通過資料庫中使用者資訊進行驗證登陸。
1.3. SQL Script
1) 建立使用者資訊表USER_ACCOUNT
create table USER_ACCOUNT ( USER_NAME VARCHAR2(30) not null, PASSWORD VARCHAR2(30) not null, USER_TYPE VARCHAR2(10) not null, ACTIVE VARCHAR2(1) not null, EMAIL VARCHAR2(64) not null, FULL_NAME VARCHAR2(64) not null ) ;
alter table USER_ACCOUNT add constraint USER_ACCOUNT_PK primary key (USER_NAME) ; alter table USER_ACCOUNT add constraint USER_ACCOUNT_UK unique (EMAIL) ;
-----------------------------------
insert into user_account (USER_NAME, PASSWORD, USER_TYPE, ACTIVE, EMAIL, FULL_NAME) values ('tom', 'tom123', 'admin', 'Y', 'tom@example.com', 'Tom');
insert into user_account (USER_NAME, PASSWORD, USER_TYPE,ACTIVE, EMAIL, FULL_NAME) values ('jerry', 'jerry123', 'user', 'Y', 'jerry@example.com', 'Jerry');
insert into user_account (USER_NAME, PASSWORD, USER_TYPE,ACTIVE, EMAIL, FULL_NAME) values ('donald', 'donald123', 'guest', 'N', 'donald@example.com', 'Donald');
Commit; |
2) 建立儲存過程PKG_SECURITY
Create Or Replace Package Pkg_Security Is Function Authenticate_User(p_User_Name Varchar2,p_Password Varchar2) Return Boolean; ----- Procedure Process_Login(p_User_Name Varchar2 ,p_Password Varchar2 ,p_App_Id Number);
End Pkg_Security; / Create Or Replace Package Body Pkg_Security Is Function Authenticate_User(p_User_Name Varchar2 ,p_Password Varchar2) Return Boolean As v_Password User_Account.Password%Type; v_Active User_Account.Active%Type; v_Email User_Account.Email%Type; Begin If p_User_Name Is Null Or p_Password Is Null Then -- Write to Session, Notification must enter a username and password 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 Where u.User_Name = p_User_Name; Exception When No_Data_Found Then -- Write to Session, User not found. Apex_Util.Set_Session_State('LOGIN_MESSAGE','User not found'); Return False; End; If v_Password <> p_Password Then -- Write to Session, Password incorrect. Apex_Util.Set_Session_State('LOGIN_MESSAGE','Password incorrect'); Return False; End If; If v_Active <> 'Y' Then Apex_Util.Set_Session_State('LOGIN_MESSAGE','User locked, please contact admin'); Return False; End If; --- -- Write user information to Session. -- Apex_Util.Set_Session_State('SESSION_USER_NAME',p_User_Name); Apex_Util.Set_Session_State('SESSION_EMAIL',v_Email); --- --- Return True; End;
-------------------------------------- Procedure Process_Login(p_User_Name Varchar2 ,p_Password Varchar2 ,p_App_Id Number) As v_Result Boolean := False; Begin v_Result := Authenticate_User(p_User_Name,p_Password); If v_Result = True Then -- Redirect to Page 1 (Home Page). Wwv_Flow_Custom_Auth_Std.Post_Login(p_User_Name -- p_User_Name ,p_Password -- p_Password ,v('APP_SESSION') -- p_Session_Id ,p_App_Id || ':1' -- p_Flow_page ); Else -- Login Failure, redirect to page 101 (Login Page). Owa_Util.Redirect_Url('f?p=&APP_ID.:101:&SESSION.'); End If; End;
End Pkg_Security; / |
1.4. Declaring Application Items
3) 在應用程式中,點選“共享元件”》“應用程式項”;
應用程式項定義: 使用應用程式項可以維護會話狀態。應用程式項可以通過使用計算, 處理或在 URL 中傳遞值來設定。使用 "新建例項時" 計算可以為會話設定一次項值。使用應用程式項可以維護未顯示並且未指定給任何頁的會話狀態。 |
4) 點選“建立”按鈕:
輸入對應屬性值:
名稱:LOGIN_MESSAGE
範圍:Application
然後點選右上方“建立應用程式項”;
應用程式項可在後期被PL/SQL中呼叫,
如:Apex_Util.Set_Session_State('LOGIN_MESSAGE','User not found');
同樣,再建立兩個應用程式項:
· SESSION_USER_NAME
· SESSION_EMAIL
1.5. Custom Authentication
5) 在應用程式中編輯“登入頁”,登入頁頁碼為101;
6) 右擊“Content Body”建立新區域。
7) 選中新區域,修改屬性值:
標識》標題:LOGIN_MESSAGE
標識》型別:靜態內容
源》文字:&LOGIN_MESSAGE. 注意結尾帶”.”,如沒有將不能返回變數值。
服務端條件》型別:項不為空值
服務端條件》項:選擇應用程式項:LOGIN_MESSAGE
8) 左側導航欄切換到“處理“標籤頁,替換”處理“》”處理“》”Login”,修改其中“源”》“PL/SQL 程式碼”,
預設值:--apex_authentication.login(p_username => :P101_USERNAME,p_password => :P101_PASSWORD );
替換值:Pkg_Security.Process_Login(:P101_USERNAME,:P101_PASSWORD,:APP_ID);
9) 儲存並執行測試;
附測試表中使用者資訊
使用者名稱 使用者密碼 使用者狀態
tom tom123 Y
jerry jerry123 Y
donald donald123 N
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29519108/viewspace-2156515/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用者登陸驗證資訊的資料結構設計資料結構
- 用觸發器記錄資料庫使用者登陸資訊觸發器資料庫
- 資料庫會話記錄使用者登陸的密碼資訊資料庫會話密碼
- 解決Mysql中只能通過localhost登陸不能通過ip登陸的問題MySqllocalhost
- AJAX+JAVA使用者登陸註冊驗證Java
- 登入介面:從資料庫中獲取資訊驗證登入(與註冊介面相聯絡)資料庫
- ogg登陸資料庫使用者密碼加密資料庫密碼加密
- 通過session模擬登陸Session
- curl模擬請求、登陸以及帶驗證碼登陸
- 1.6.5.2. 通過密碼檔案驗證連線資料庫密碼資料庫
- 通過selenium突破極驗驗證實現登入
- 非Oracle使用者使用作業系統驗證登陸(/ as sysdba)Oracle作業系統
- asp.net mvc中的使用者登入驗證過濾器ASP.NETMVC過濾器
- 限制資料庫登陸trigger資料庫
- 登陸資訊顯示資料 : /etc/issue and /etc/motd
- sqlnet.ora 驗證oracle 登陸方式SQLOracle
- 關於資料庫登陸名和資料庫使用者名稱的一點點心得資料庫
- 按 F12獲取登陸資料,一鍵登陸巴西衛生部資料庫資料庫
- 使用plsql develop內網登陸資料庫SQLdev內網資料庫
- 通過Java程式測試資料庫連線資訊Java資料庫
- 通過連線檢視資料庫相關資訊資料庫
- 驗證使用者輸入的口令是否與資料庫中的匹配資料庫
- PHP學習筆記(七):前臺使用者登陸、後臺匹配資料庫進行校驗PHP筆記資料庫
- SpringSceurity(5)---簡訊驗證碼登陸功能Spring
- 登陸介面模組解析——生成圖片驗證碼
- 9.Django之登陸註冊驗證登出Django
- jquery登陸表單簡單驗證程式碼jQuery
- SQL資料庫使用者只有“名稱”而無“登陸名”解決SQL資料庫
- 解鎖資料庫使用者、檢視登陸幾次才鎖定使用者資料庫
- 基於外部OS驗證的資料庫使用者資料庫
- 利用基於 NTP 的 TOTP 演算法缺陷繞過 WordPress 登陸驗證演算法
- 驗證資料庫中URL的有效性資料庫
- vue通過vue-router攔截實現登入驗證Vue
- 記在dcat-admin中,登陸頁面加驗證碼操作
- 審計資料庫登陸登出觸發器資料庫觸發器
- PHP註冊登入:包括資料存入資料庫,生成隨機驗證碼PHP資料庫隨機
- 通過觸發器記錄資料庫連線資訊觸發器資料庫
- 通過shell指令碼得到資料庫的基本資訊(一)指令碼資料庫