ORACLE密码策略验证程序
发布时间:2010/11/26 16:55:03 来源:城市学习网 编辑:ziteng
ORACLE密码策略非常重要,下面就为您详细介绍ORACLE密码策略验证程序,如果您对ORACLE密码策略方面感兴趣的话,不妨一看。
密码字符串要求:
-- Check if the password is same as the username
-- Check for the minimum length of the password
-- Check if the password contains at least one letter, one digit and one
-- Check if the password differs from the previous password by at least
CREATE OR REPLACE FUNCTION SYS.verify_function
(username varchar2,
password varchar2,
old_password varchar2)
RETURN boolean IS
n boolean;
m integer;
differ integer;
isdigit boolean;
ischar boolean;
ispunct boolean;
digitarray varchar2(20);
punctarray varchar2(25);
chararray varchar2(52);
BEGIN
digitarray:= ’0123456789’;
chararray:= ’abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
punctarray:=’!"#$%&()``*+,-/:;<=>?_’;
-- Check if the password is same as the username
IF NLS_LOWER(password) = NLS_LOWER(username) THEN
raise_application_error(-20001, ’Password same as or similar to user’);
END IF;
-- Check for the minimum length of the password
IF length(password) < 8 THEN
raise_application_error(-20002, ’Password length less than 8’);
END IF;
-- Check if the password is too simple. A dictionary of words may be
-- maintained and a check may be made so as not to allow the words
-- that are too simple for the password.
IF NLS_LOWER(password) IN (’welcome’, ’database’, ’account’, ’user’, ’password’, ’oracle’, ’computer’, ’abcd’) THEN
raise_application_error(-20002, ’Password too simple’);
END IF;
-- Check if the password contains at least one letter, one digit and one
-- punctuation mark.
-- 1. Check for the digit
1.isdigit:=FALSE;
2.m := length(password);
3.FOR i IN 1..10 LOOP
4.FOR j IN 1..m LOOP
5.IF substr(password,j,1) = substr(digitarray,i,1) THEN
6.isdigit:=TRUE;
7.GOTO findchar;
8.END IF;
9.END LOOP;
10.END LOOP;
11.IF isdigit = FALSE THEN [NextPage] 12.raise_application_error(-20003, ’Password should contain at least one digit, one character and one punctuation’);
13.END IF;
-- 2. Check for the character
1.<<findchar>>
2.ischar:=FALSE;
3.FOR i IN 1..length(chararray) LOOP
4.FOR j IN 1..m LOOP
5.IF substr(password,j,1) = substr(chararray,i,1) THEN
6.ischar:=TRUE;
7.GOTO findpunct;
8.END IF;
9.END LOOP;
10.END LOOP;
11.IF ischar = FALSE THEN
12.raise_application_error(-20003, ’Password should contain at least one
13.digit, one character and one punctuation’);
14.END IF;
-- 3. Check for the punctuation
1.<<findpunct>>
2.ispunct:=FALSE;
3.FOR i IN 1..length(punctarray) LOOP
4.FOR j IN 1..m LOOP
5.IF substr(password,j,1) = substr(punctarray,i,1) THEN
6.ispunct:=TRUE;
7.GOTO endsearch;
8.END IF;
9.END LOOP;
10.END LOOP;
11.IF ispunct = FALSE THEN
12.raise_application_error(-20003, ’Password should contain at least one
13.digit, one character and one punctuation’);
14.END IF;
15.
16.<<endsearch>>
17.-- Check if the password differs from the previous password by at least
18.-- 3 letters
19.IF old_password IS NOT NULL THEN
20.differ := length(old_password) - length(password);
21.
22.IF abs(differ) < 3 THEN
23.IF length(password) < length(old_password) THEN
24.m := length(password);
25.ELSE
26.m := length(old_password);
27.END IF;
28.
29.differ := abs(differ);
30.FOR i IN 1..m LOOP
31.IF substr(password,i,1) != substr(old_password,i,1) THEN
32.differ := differ + 1;
33.END IF;
34.END LOOP;
35.
36.IF differ < 3 THEN
37.raise_application_error(-20004, ’Password should differ by at
38.least 3 characters’);
39.END IF;
40.END IF;
41.END IF;
42.-- Everything is fine; return TRUE ;
43.RETURN(TRUE);
44.END;