We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Strings
- Strong Password
- Discussions
Strong Password
Strong Password
+ 23 comments def minimumNumber(n, password): count = 0 if any(i.isdigit() for i in password)==False: count+=1 if any(i.islower() for i in password)==False: count+=1 if any(i.isupper() for i in password)==False: count+=1 if any(i in '!@#$%^&*()-+' for i in password)==False: count+=1 return max(count,6-n)
+ 4 comments C++ folks:
bitset
is your friend here:int CharFamily(char c) { if(c >= '0' && c <= '9') return 0; if(c >= 'a' && c <= 'z') return 1; if(c >= 'A' && c <= 'Z') return 2; return 3; } int main() { int n; cin >> n; char c; bitset<4> mask; while (cin >> c) { mask.set(CharFamily(c)); } cout << max(6-n, 4-(int)mask.count()); }
+ 4 comments This is my Solution (Java 8)
private static int checkPass(String s) { int count = 0; Pattern patternDigit = Pattern.compile("(\\d)"); Pattern patternUpper = Pattern.compile("([A-Z])"); Pattern patternLower = Pattern.compile("([a-z])"); Pattern patternSpecial = Pattern.compile("(\\W)"); Matcher matcherDigit = patternDigit.matcher(s); Matcher matcherUpper = patternUpper.matcher(s); Matcher matcherLower = patternLower.matcher(s); Matcher matcherSpecial = patternSpecial.matcher(s); if (!matcherDigit.find()) { count++; } if (!matcherUpper.find()) { count++; } if (!matcherLower.find()) { count++; } if (!matcherSpecial.find()) { count++; } if ((count+s.length())<6) { count = count + 6-(count+s.length()); } return count; }
+ 1 comment Loled hard as I saw the amount of test cases. :D
+ 7 comments Similar logic implemented without looping, using Regular Expressions in Java.
static int minimumNumber(int n, String password) { int lc=0,uc=0,no=0,sc=0; int sum=0; String lowercase = ".*[a-z]+.*"; String uppercase = ".*[A-Z]+.*"; String num = ".*[0-9]+.*"; String specialchar = ".*[-!@#$%^&*()+]+.*"; //Regex for pattern matching if(!(password.matches(lowercase))) lc++; //if there is no match to a lowercase,"lc" is increased by 1. if(!(password.matches(uppercase))) uc++; //if there is no match to an uppercase,"uc" is increased by 1. if(!(password.matches(num))) no++; //if there is no match to a number,"no" is increased by 1. if(!(password.matches(specialchar))) sc++; //if there is no match to a specialCharacter,"sc" is increased by 1. sum=lc+uc+sc+no; return (sum>(6-n))?sum:(6-n); }
Load more conversations
Sort 655 Discussions, By:
Please Login in order to post a comment