Strong Password

  • + 0 comments

    Perl solution:

    sub minimumNumber {
        my ($n, $str) = @_;
        my $cnt = 0;
        $cnt++ if ($str !~ m/[a-z]/m);
        $cnt++ if ($str !~ m/[A-Z]/m);
        $cnt++ if ($str !~ m/[\!\@\#\$\%\^\&\*\(\)\-\+]/m);
        $cnt++ if ($str !~ m/\d+/m);
        if ($n < 6) {
            if ((length($str) + $cnt) < 6) {
                $cnt = 6 - length($str);
            }        
        }
        
        return $cnt;
    
    }