重庆oracle认证培训机构

新闻分类

产品分类

热门关键词

联系我们

企业名称:重庆赛烽达科技有限公司

联系人:程老师

手机:13372708242

邮箱:xqzhang@saifengda.com

网址:www.cqora.com

地址:重庆石桥铺高创锦业17-3

重庆oracle培训课程:oracle用户名密码限制函数verify_function

您的当前位置: 首 页 >> 新闻资讯 >> 常见问题

重庆oracle培训课程:oracle用户名密码限制函数verify_function

发布日期:2018-09-27 作者: 点击:


CREATE OR REPLACE FUNCTION 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 “检查密码的长度(不能小于4位)”

   IF length(password) < 4 THEN

      raise_application_error(-20002, 'Password length less than 4');

   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. “密码简单的话报错,如'welcome', 'database', 'account', 'user', 'password', 'oracle', 'computer', 'abcd'等都简单,可以自己定义”

   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

   isdigit:=FALSE;

   m := length(password);

   FOR i IN 1..10 LOOP

      FOR j IN 1..m LOOP

         IF substr(password,j,1) = substr(digitarray,i,1) THEN

            isdigit:=TRUE;

             GOTO findchar;

         END IF;

      END LOOP;

   END LOOP;

   IF isdigit = FALSE THEN

      raise_application_error(-20003, 'Password should contain at least one digit, one character and one punctuation');

   END IF;

   -- 2. Check for the character

   <<findchar>>

   ischar:=FALSE;

   FOR i IN 1..length(chararray) LOOP

      FOR j IN 1..m LOOP

         IF substr(password,j,1) = substr(chararray,i,1) THEN

            ischar:=TRUE;

             GOTO findpunct;

         END IF;

      END LOOP;

   END LOOP;

   IF ischar = FALSE THEN

      raise_application_error(-20003, 'Password should contain at least one

              digit, one character and one punctuation');

   END IF;

   -- 3. Check for the punctuation

   <<findpunct>>

   ispunct:=FALSE;

   FOR i IN 1..length(punctarray) LOOP

      FOR j IN 1..m LOOP

         IF substr(password,j,1) = substr(punctarray,i,1) THEN

            ispunct:=TRUE;

             GOTO endsearch;

         END IF;

      END LOOP;

   END LOOP;

   IF ispunct = FALSE THEN

      raise_application_error(-20003, 'Password should contain at least one

              digit, one character and one punctuation');

   END IF;


   <<endsearch>>

   -- Check if the password differs from the previous password by at least

   -- 3 letters

   IF old_password IS NOT NULL THEN

     differ := length(old_password) - length(password);


     IF abs(differ) < 3 THEN

       IF length(password) < length(old_password) THEN

         m := length(password);

       ELSE

         m := length(old_password);

       END IF;


       differ := abs(differ);

       FOR i IN 1..m LOOP

         IF substr(password,i,1) != substr(old_password,i,1) THEN

           differ := differ + 1;

         END IF;

       END LOOP;


       IF differ < 3 THEN

         raise_application_error(-20004, 'Password should differ by at

         least 3 characters');

       END IF;

     END IF;

   END IF;

   -- Everything is fine; return TRUE ;

   RETURN(TRUE);

END;


本文网址:http://www.cqora.com/news/588.html

关键词:

最近浏览:

相关产品:

相关新闻:

报名咨询

点击咨询报名

赛烽达QQ群

赛烽达技术群

程老师

xxxxxxxxxx

加微信咨询

张老师微信.jpg

xqzhang@saifengda.com