Strong Password

Sort by

recency

|

906 Discussions

|

  • + 0 comments

    Here is my c++ solution, the explanation is here : https://youtu.be/t0O-Knlq4lQ

    char getNature(char c){
        if(c >= '0' && c <='9') return 'n';
        if(c >= 'a' && c <= 'z') return 'l';
        if(c >= 'A' && c <= 'Z') return 'u';
        return 's';
    }
    
    int minimumNumber(int n, string password) {
        map<char, int> mp;
        for(char c: password){
            mp[getNature(c)] = 1;
        }
        return max(4 - (int)mp.size(), 6 - n); 
    }
    
  • + 0 comments
    def minimumNumber(n):
        low=1
        up=1
        di=1
        spl=1
    
        for i in n:
            if i.islower():
                low=0
            elif i.isupper():
                up=0
            elif i.isdigit():
                di=0
            elif i in '!@#$%^&*()-+':
                spl=0
        ans=low+up+di+spl
        if len(n)+ans<6:
            ans+=6-(len(n)+ans)
            
        return ans
    
  • + 0 comments

    Here is my JAVA solution

    public static int minimumNumber(int n, String password) {
            // Return the minimum number of characters to make the password strong
            int counter = 0;
            String numbers = "0123456789";
            String lowerCase = "abcdefghijklmnopqrstuvwxyz";
            String upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            String specialCharacters = "!@#$%^&*()-+";
            
            boolean hasNumber = false;
            boolean hasLowerCase = false;
            boolean hasUpperCase = false;
            boolean hasSpecialCharacter = false;
            
            for (int i = 0; i < password.length(); i++) {
                char value = password.charAt(i);
                if (numbers.indexOf(value) >= 0) {
                    hasNumber = true;
                } else if (lowerCase.indexOf(value) >= 0) {
                    hasLowerCase = true;
                } else if (upperCase.indexOf(value) >= 0) {
                    hasUpperCase = true;
                } else if (specialCharacters.indexOf(value) >= 0) {
                    hasSpecialCharacter = true;
                }
            }
            
            if (!hasNumber) counter++;
            if (!hasLowerCase) counter++;
            if (!hasUpperCase) counter++;
            if (!hasSpecialCharacter) counter++;
            
            if (n < 6) {
                return counter > (6 - n) ? counter : (6 - n);
            }
            
            return counter;
        }
    
  • + 0 comments

    is it a good idea to use it for my Ethnic rhinoplasty in Turkey project? I'm a web developer and running it on a wordpress CMS.

  • + 0 comments

    Here is my C solution

    int minimumNumber(int n, string password) {
        // Return the minimum number of characters to make the password strong
        bool numFlag = 0, lowFlag = 0, upFlag = 0, speFlag = 0;
        int minNum = 0;
        for(int i = 0 ;i<n;i++){
            if(password[i] >= '0' && password[i] <='9')
                numFlag = 1;
            else if(password[i] >= 'a' && password[i] <='z')
                lowFlag = 1;
            else if(password[i] >= 'A' && password[i] <='Z')
                upFlag = 1;
            else if(!speFlag && (password[i] == '!' || password[i] =='@' || password[i] == '#' || password[i] =='$' ||
                    password[i] == '%' || password[i] =='^' || password[i] == '&' || password[i] =='*' ||
                    password[i] == '(' || password[i] ==')' || password[i] == '-' || password[i] =='+'))
                        speFlag = 1;            
        }
        if(numFlag == 0)
            minNum++;
        if(lowFlag == 0)
            minNum++;
        if(upFlag == 0)
            minNum++;
        if(speFlag == 0)
            minNum++;    
        if((n + minNum) < 6)        
            minNum+=(6-n-minNum);
        
        return minNum;
    
    }