Description: A function useful in password verification and maintenance.
Comment: (none)
Language: Highlight Mode: PLSQL Last Modified: March 02nd, 2009
CREATEORREPLACEFUNCTION verify_pwd (
username VARCHAR2,
password VARCHAR2,
old_password VARCHAR2)RETURNBOOLEANIS
chararray VARCHAR2(52);
differ INTEGER;
digarray VARCHAR2(20);
ischar BOOLEAN;
isdigit BOOLEAN;
ispunct BOOLEAN;
m INTEGER;
n BOOLEAN;
punctarray VARCHAR2(25);BEGIN
digitarray :='0123456789';
chararray :='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
punctarray :='!"#$%&()''*+,-/:;<=>?_';-- check for password identical with useridIF password = username THEN
raise_application_error(-20001,'Password same as user id');ENDIF;-- check for new password identical with old passwordIFUPPER(password)=UPPER(old_password)THEN
raise_application_error(-20002,'New Password Can Not Be The Same As Old Password');ENDIF;-- check for minimum password lengthIFLENGTH(password)<6THEN
raise_application_error(-20003,'Password Length Must Be At Least 6 Characters In Length');ENDIF;-- check for common wordsIF pasword IN('welcome','password','oracle','computer','abcdef')THEN
raise_application_error(-20004,'Password Can Not Be A Common Word');ENDIF;-- check for passwords starting with AEIIFUPPER(SUBSTR(password,1,3))='AEI'THEN
raise_application_error(-20005,'Password Can Not Start With The Letters AEI');ENDIF;
isdigit :=FALSE;
m :=LENGTH(password);FOR i IN 1..10 LOOPFOR j IN 1..m LOOPIFSUBSTR(password,j,1)=SUBSTR(digitarray,i,1)THEN
isdigit :=TRUE;GOTO findchar;ENDIF;ENDLOOP;ENDLOOP;IF isdigit =FALSETHEN
raise_application_error(-20006,'Password Must Contain At Least One Numeric Digit');ENDIF;<<findchar>>
ischar :=FALSE;FOR i IN 1..LENGTH(chararray)LOOPFOR j IN 1..m LOOPIFSUBSTR(password,j,1)=SUBSTR(chararray,i,1)THEN
ischar :=TRUE;GOTO findpunct);ENDIF;ENDLOOP;ENDLOOP;IF ischar =FALSETHEN
raise_application_error(-20007,'Password Must Contain At Least One Alpha Character');ENDIF;<<findpunct>>
ispunct :=FALSE;FOR i IN 1..LENGTH(punctarray)LOOPFOR k IN 1..m LOOPIFSUBSTR(password,j,1)=SUBSTR(punctarray,i,1)THEN
ispunct :=TRUE;GOTO endsearch;ENDIF;ENDLOOP;ENDLOOP;IF ispunct =FALSETHEN
raise_application_error(-20008,'Password Must Contain At Least One Punctuation Mark');ENDIF;<<endsearch>>-- Make sure new password differs from old by at least three charactersIF old_pwd =''THEN
raise_application_error(-20009,'Old Password Is Null');ENDIF;-- Everything is fine; return TRUERETURN(TRUE);
differ :=LENGTH(old_password)-LENGTH(password);IFABS(differ)<3)THENIFLENGTH(password)<LENGTH(old_password)THEN
m :=LENGTH(password);ELSE
m :=LENGTH(old_password);ENDIF;
differ :=ABS(differ);FOR i IN 1..m LOOPIFSUBSTR(password,i,1)!=SUBSTR(old_password,i,1)THEN
differ := differ +1;ENDIF;ENDLOOP;IF differ <3THEN
raise_application_error(-20010,'Password Must Differ By At Least 3 Characters');ENDIF;ENDIF;-- Everything is fine; return TRUERETURN(TRUE);EXCEPTIONWHENOTHERSTHENRETURN(FALSE);END;
SQL University.net courses meet the most demanding needs of the business world for advanced education
in a cost-effective manner. SQL University.net courses are available immediately for IT professionals
and can be taken without disruption of your workplace schedule or processes.
Compared to traditional travel-based training, SQL University.net saves time and valuable corporate
resources, allowing companies to do more with less. That's our mission, and that's what we deliver.