Strong Password

Sort by

recency

|

926 Discussions

|

  • + 0 comments

    Python Code Solution

    def minimumNumber(n:int, password:str):
        conditions = {"numbers":0,"lower_case":0,"upper_case":0,"special_characters":0}
        for letter in range(n):
            if password[letter].isdigit():
                conditions["numbers"] +=1
            elif password[letter].islower():
                conditions["lower_case"] +=1
            elif password[letter].isupper():
                conditions["upper_case"] +=1
            elif password[letter].isalnum() == False:
                conditions["special_characters"] +=1
        missing_types = len([v for v in conditions.values() if v == 0])
        return max(missing_types, 6 - n)
    
  • + 0 comments

    My Solution in C :

    int isDigit(char ch){
        return (ch>='0' && ch<='9')?1:0;
    }
    
    int isLower(char ch){
        return (ch>='a' && ch<='z')?1:0;
    }
    
    int isUpper(char ch){
        return (ch>='A' && ch<='Z')?1:0;
    }
    
    
    int minimumNumber(int n, char* password) {
        int has_digit = 0;
        int has_lowercase = 0;
        int has_uppercase = 0;
        int has_special = 0;
        char *pass = password;
        char special_chars[] = "!@#$%^&*()-+";
    
        while(*pass){
            if(isDigit(*pass))
                has_digit=1;
            else if(isLower(*pass))
                has_lowercase=1;
            else if(isUpper(*pass))
                has_uppercase=1;
            else{
                for(int i=0; i<strlen(special_chars);i++){
                    if(special_chars[i]==*pass){
                        has_special=1;
                        break;
                    }
                }
            }
            pass++;
        }
    
        int missing_types = 0;
        if (!has_digit)
            missing_types++;
        if (!has_lowercase)
            missing_types++;
        if (!has_uppercase)
            missing_types++;
        if (!has_special)
            missing_types++;
    
        int needed_for_length = 0;
        if (n < 6) {
            needed_for_length = 6 - n;
        }
        int max=0;
        if(needed_for_length>missing_types)
            max = needed_for_length;
        else
            max = missing_types;
        return max;
    }
    

    `

  • + 0 comments
    def minimumNumber(n, password):
        # Return the minimum number of characters to make the password strong
        len_required = 6
        has_digit = False
        has_lower_case = False
        has_upper_case = False
        has_special_char = False 
        special_char = set("!@#$%^&*()-+")
        char_required = 4
        for i in password:
            if "0" <= i <= "9" and not has_digit:
                has_digit = True
                char_required -= 1
            elif "a" <= i <= "z" and not has_lower_case:
                has_lower_case = True
                char_required -= 1
            elif "A" <= i <= "Z" and not has_upper_case:
                has_upper_case = True
                char_required -= 1
            elif i in special_char and not has_special_char:
                has_special_char = True
                char_required -= 1
                
        if n >= len_required:
            return char_required
            
        len_diff = len_required - n
                     
        return len_diff if len_diff > char_required else char_required
    
  • + 0 comments

    **Here is problem solution in python java c++ c and Javascript **- https://programmingoneonone.com/hackerrank-strong-password-problem-solution.html

  • + 0 comments

    Python 3

    def minimumNumber(n, password):
        count = 0
        
        if not any(i.isdigit() for i in password):
            count += 1
        if not any(i.islower() for i in password):
            count += 1
        if not any(i.isupper() for i in password):
            count += 1
        if not any(i in "!@#$%^&*()-+" for i in password):
            count += 1
            
        return max(6 - n, count)