Strong Password

  • + 0 comments

    c++

    int minimumNumber(int n, string password) {
        // Return the minimum number of characters to make the password strong
        bool UP =0, down =0, digit =0, special =0;
        unsigned int result1 =4, res2 =0; 
        
        for (int i=0;i<n;i++) {
            if (password.at(i) <= 'z' and password.at(i) >= 'a') {
                down = 1;
            }
            if (password.at(i) <= '9' and password.at(i) >= '0') {
                digit = 1;
            }
            if (password.at(i) <= 'Z' and password.at(i) >= 'A') {
                UP = 1;
            }
            if ((password.at(i) <= '+' and
                password.at(i) >= '!')or(password.at(i)=='^')or(password.at(i)=='-')
                or (password.at(i)=='@')){
                special = 1;
            }
        }
        res2 = UP+down+digit+special;
        if (n>=6) {
        result1 -= res2;
        }
        if(n == 5 and res2 ==0) {
            result1 = res2+1;
        }
        if(n == 5 and res2 >=1) {
            result1 = result1 - res2;
        }
        if(n == 5 and res2 == 4) {
            result1 = 6-n;
        }
        if (n==4) {
            result1 = res2+2;
        }
        if (n==4 and res2 >=2) {
            result1 = res2;         
        }
        if (n==4 and res2 >=3) {
            result1 = 6-n;
        }
        if (n<=3) {
            result1 = 6-n;
        }
        return result1;
    }