0

Problem: Password validation

HERE IS MY SOLUTION. I READ IT A MILLION TIMES AND STILL DON’T GET, WHERE THE BUG IS. IT ONLY MISSES 2 CASES. I’LL BE GLAD IF SOMEONE POINTS OUT MY MISTAKE. #include <bits/stdc++.h> using namespace std; string pass; char spec[] = { '!', '@', '#', '

#x27;, '%', '&', '*' }; bool isLongEnough() { return pass.size() >= 7; } bool isWithNumbersAndSpecials() { int count = 0; int spec1 = -1; int spec2 = -1; for(int i = 0; i < pass.size(); i++) { if(pass[i] >= '0' && pass[i] <= '9') { count++; } for(int j = 0; j < 7; j++) { if(pass[i] == spec[j]) { if(spec1 != -1 && pass[i] != pass[spec1]) { spec2 = i; } if(spec1 == -1) { spec1 = i; } break; } } } return count >= 2 && spec2 != -1; } int main() { getline(cin, pass); if(isLongEnough() && isWithNumbersAndSpecials()) { cout <<"Strong" <<endl; } else { cout <<"Weak" <<endl; } return 0; }

21st Jul 2020, 11:55 PM
Kristiyan Garchev
Kristiyan Garchev - avatar
5 Answers
+ 3
Kristiyan Garchev the question specifies that the password is strong if it have any two characters are special characters ( they need not to be distinct) Your code fails on test case like this :- 12@@abcde Your output -> Weak Expected output -> Strong A simple fix is to remove that condition from your if statement 👇 https://code.sololearn.com/cCMd3trLpq3k/?ref=app
22nd Jul 2020, 12:57 AM
Arsenic
Arsenic - avatar
+ 1
Thank you, Arsenic !
22nd Jul 2020, 12:59 AM
Kristiyan Garchev
Kristiyan Garchev - avatar
0
Is it possible for you to show me your code?
22nd Jul 2020, 12:01 AM
Maromon Lupus
Maromon Lupus - avatar
0
Sorry, can you see it now?
22nd Jul 2020, 12:41 AM
Kristiyan Garchev
Kristiyan Garchev - avatar
- 1
Mention language too.
23rd Jul 2020, 1:05 PM
shubham kumar
shubham kumar - avatar