how do I modify a function to include password complexity of not having more than 3 characters of the same class consecutively

I have a function that checks for strong password during user creation. I need to include a rule that the password should have no more than 3 characters of the same class
for example the password should not contain 4 lower case char, 4 numbers, 4 special characters consecutively

Below the function:

BEGIN
    -- 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) < 12
    THEN
        RAISE_APPLICATION_ERROR(-20002, 'Password length less than 12');
    END IF;

    -- check for 2 digits
    IF REGEXP_INSTR(
           password,
           '[0-9]',
           1,
           2
       ) = 0
    THEN
        RAISE_APPLICATION_ERROR(-20003, 'Password should contain at least 2 digits');
    END IF;

    -- check for 2 upper
    IF REGEXP_INSTR(
           password,
           '[A-Z]',
           1,
           2
       ) = 0
    THEN
        RAISE_APPLICATION_ERROR(-20004, 'Password should contain at least 2 upper-case characters');
    END IF;

    -- check for 2 lower
    IF REGEXP_INSTR(
           password,
           '[a-z]',
           1,
           2
       ) = 0
    THEN
        RAISE_APPLICATION_ERROR(-20005, 'Password should contain at least 2 lower-case characters');
    END IF;

    -- check for 2 special
    IF REGEXP_INSTR(
           password,
           '["#$%&()!`*+,-/:;<=>?_]',
           1,
           2
       ) = 0
    THEN
        RAISE_APPLICATION_ERROR(-20003, 'Password should contain at least 2 special characters');
    END IF;

    RETURN TRUE;
END;

How do I modify it to include this rule?
sikyalaSenior Database AdministratorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sdstuberCommented:
try this...

CREATE OR REPLACE FUNCTION verify_function_11g(
    username        VARCHAR2,
    password        VARCHAR2,
    old_password    VARCHAR2
)
    RETURN BOOLEAN
IS
    n               BOOLEAN;
    m               INTEGER;
    differ          INTEGER;
    db_name         VARCHAR2(40);
    i_char          VARCHAR2(10);
    simple_password VARCHAR2(10);
    reverse_user    VARCHAR2(32);
BEGIN
    -- 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) < 12
    THEN
        RAISE_APPLICATION_ERROR(-20002, 'Password length less than 12');
    END IF;

    -- check for 2 digits
    IF REGEXP_INSTR(
           password,
           '[0-9]',
           1,
           2
       ) = 0
    THEN
        RAISE_APPLICATION_ERROR(-20003, 'Password should contain at least 2 digits');
    END IF;

    -- check for 2 upper
    IF REGEXP_INSTR(
           password,
           '[A-Z]',
           1,
           2
       ) = 0
    THEN
        RAISE_APPLICATION_ERROR(-20004, 'Password should contain at least 2 upper-case characters');
    END IF;

    -- check for 2 lower
    IF REGEXP_INSTR(
           password,
           '[a-z]',
           1,
           2
       ) = 0
    THEN
        RAISE_APPLICATION_ERROR(-20005, 'Password should contain at least 2 lower-case characters');
    END IF;

    -- check for 2 special
    IF REGEXP_INSTR(
           password,
           '["#$%&()!`*+,-/:;<=>?_]',
           1,
           2
       ) = 0
    THEN
        RAISE_APPLICATION_ERROR(-20003, 'Password should contain at least 2 special characters');
    END IF;

    -- check for 4 or more consecutive digits
    IF REGEXP_INSTR(password, '[0-9]{4,}') != 0
    THEN
        RAISE_APPLICATION_ERROR(-20003, 'Password should not contain 4 consecutive digits');
    END IF;

    -- check for 4 or more consecutive upper
    IF REGEXP_INSTR(password, '[A-Z]{4,}') != 0
    THEN
        RAISE_APPLICATION_ERROR(
            -20004,
            'Password should not contain 4 consecutive upper-case characters'
        );
    END IF;

    -- check for 4 or more consecutive lower
    IF REGEXP_INSTR(password, '[a-z]{4,}') != 0
    THEN
        RAISE_APPLICATION_ERROR(
            -20005,
            'Password should not contain 4 consecutive lower-case characters'
        );
    END IF;

    -- check for 4 or more consecutive special
    IF REGEXP_INSTR(password, '["#$%&()!`*+,-/:;<=>?_]{4,}') != 0
    THEN
        RAISE_APPLICATION_ERROR(
            -20003,
            'Password should not contain 4 consecutive special characters'
        );
    END IF;

    RETURN TRUE;
END;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sikyalaSenior Database AdministratorAuthor Commented:
excellent!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.