在Oracle中可以很方便的自定義密碼驗(yàn)證函數(shù),用來檢驗(yàn)用戶的新密碼是否符合安全標(biāo)準(zhǔn)。
10年積累的網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先建設(shè)網(wǎng)站后付款的網(wǎng)站建設(shè)流程,更有凌源免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
下面是一個(gè)最簡(jiǎn)單的自定義驗(yàn)證函數(shù)的例子:
SQL> CONN / AS SYSDBA
已連接。
SQL> CREATE OR REPLACE FUNCTION F_MY_VERIFY
2 (P_USERNAME IN VARCHAR2, P_PASSWORD IN VARCHAR2, P_OLD_PASSWORD IN VARCHAR2)
3 RETURN BOOLEAN AS
4 BEGIN
5 IF P_PASSWORD = P_OLD_PASSWORD THEN
6 RAISE_APPLICATION_ERROR(-20001, 'NEW PASSWORD SAME AS OLD PASSWORD.');
7 END IF;
8
9 IF P_PASSWORD = P_USERNAME THEN
10 RAISE_APPLICATION_ERROR(-20002, 'PASSWORD SAME AS USERNAME.');
11 END IF;
12
13 IF INSTR(P_PASSWORD, P_OLD_PASSWORD, 1) > 0 OR INSTR(P_OLD_PASSWORD, P_PASSWORD, 1) > 0 THEN
14 RAISE_APPLICATION_ERROR(-20003, 'NEW PASSWORD AND OLD PASSWORD ARE LIKE EACH OTHER.');
15 END IF;
16
17 IF INSTR(P_PASSWORD, P_USERNAME, 1) > 0 OR INSTR(P_USERNAME, P_PASSWORD, 1) > 0 THEN
18 RAISE_APPLICATION_ERROR(-20004, 'PASSWORD AND USERNAME ARE LIKE EACH OTHER.');
19 END IF;
20
21 IF LENGTH(P_PASSWORD) < 6 THEN
22 RAISE_APPLICATION_ERROR(-20005, 'PASSWORD TOO SHORT.');
23 END IF;
24
25 RETURN TRUE;
26 END;
27 /
函數(shù)已創(chuàng)建。
將當(dāng)前的驗(yàn)證函數(shù)設(shè)置為DEFAULT策略的驗(yàn)證函數(shù):
SQL> ALTER PROFILE DEFAULT LIMIT PASSWORD_VERIFY_FUNCTION F_MY_VERIFY;
配置文件已更改
最后檢驗(yàn)一下驗(yàn)證函數(shù)是否正常工作:
SQL> CONN U1/P_U1
已連接。
SQL> ALTER USER U1 IDENTIFIED BY P_U1 REPLACE P_U1;
ALTER USER U1 IDENTIFIED BY P_U1 REPLACE P_U1
*
第 1行出現(xiàn)錯(cuò)誤:
ORA-28007:無法重新使用口令
SQL> ALTER USER U1 IDENTIFIED BY U1 REPLACE P_U1;
ALTER USER U1 IDENTIFIED BY U1 REPLACE P_U1
*
第 1行出現(xiàn)錯(cuò)誤:
ORA-28003:指定口令的口令驗(yàn)證失敗
ORA-20002: PASSWORD SAME AS USERNAME.
SQL> ALTER USER U1 IDENTIFIED BY P_U123 REPLACE P_U1;
ALTER USER U1 IDENTIFIED BY P_U123 REPLACE P_U1
*
第 1行出現(xiàn)錯(cuò)誤:
ORA-28003:指定口令的口令驗(yàn)證失敗
ORA-20003: NEW PASSWORD AND OLD PASSWORD ARE LIKE EACH OTHER.
SQL> ALTER USER U1 IDENTIFIED BY PASS_U1 REPLACE P_U1;
ALTER USER U1 IDENTIFIED BY PASS_U1 REPLACE P_U1
*
第 1行出現(xiàn)錯(cuò)誤:
ORA-28003:指定口令的口令驗(yàn)證失敗
ORA-20004: PASSWORD AND USERNAME ARE LIKE EACH OTHER.
SQL> ALTER USER U1 IDENTIFIED BY 12345 REPLACE P_U1;
ALTER USER U1 IDENTIFIED BY 12345 REPLACE P_U1
*
第 1行出現(xiàn)錯(cuò)誤:
ORA-00988:口令缺失或無效
SQL> ALTER USER U1 IDENTIFIED BY "12345" REPLACE P_U1;
ALTER USER U1 IDENTIFIED BY "12345" REPLACE P_U1
*
第 1行出現(xiàn)錯(cuò)誤:
ORA-28003:指定口令的口令驗(yàn)證失敗
ORA-20005: PASSWORD TOO SHORT.
SQL> ALTER USER U1 IDENTIFIED BY NEW_COMPLICATE_PASSWORD REPLACE P_U1;
用戶已更改。