0

[Code Coach] Password Validation

Hey Guys, I need some help with my script for the Password Validation Challenge, as im getting only in one case a negative and i cant find the error. Can someone who finished the code tell me whats the condition of the Test Case #4? Greetings, Kami

3rd May 2020, 10:36 AM
Kami
Kami - avatar
15 Antworten
+ 2
Test case #4 it's verify length password. Your program not check out length. // not right if (input.length() < 7) { feedback(valid); } // all rights int x = input.length(); boolean a = false; if (x > 6) { a = true; } if (spchar1 == true && spchar2 == true && number1 == true && number2 == true && a == true)
5th May 2020, 4:58 AM
Smith Welder
Smith Welder - avatar
+ 3
Have you considered RegEx? That would greatly simplify things. 👍
3rd May 2020, 3:17 PM
Tony
Tony - avatar
+ 3
#include <iostream> using namespace std; int main() { int a=0,b=0,c=0,d=0; string pswrd; getline(cin,pswrd); a=pswrd.length(); for(; b<a; b++){ if(pswrd[b]=='
#x27;||pswrd[b]=='&'||pswrd[b]=='@'||pswrd[b]=='%'||pswrd[b]=='#'||pswrd[b]=='*'||pswrd[b]=='!'){ c++;} if(pswrd[b]=='1'||pswrd[b]=='2'||pswrd[b]=='3'||pswrd[b]=='4'||pswrd[b]=='5'||pswrd[b]=='6'||pswrd[b]=='7'||pswrd[b]=='8'||pswrd[b]=='9'||pswrd[b]=='0'){ d++;} } if(c>=2 && d>=2 && a>=7){ cout << "Strong"; }else { cout << "Weak"; } return 0; } //try this, maybe it helps
28th Aug 2020, 4:32 AM
ヒトリ
ヒトリ - avatar
3rd May 2020, 10:41 AM
Kami
Kami - avatar
+ 1
Show me your code
3rd May 2020, 10:39 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
+ 1
What expected result?
3rd May 2020, 10:44 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
+ 1
Smith Welder thanks, i was breaking my head at this one
5th May 2020, 6:09 AM
Kami
Kami - avatar
0
I can help you
3rd May 2020, 10:39 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
0
Thats the problem, the expected result is hidden in the results, im getting 13/14 positives and 1 negative case... As i can't see the error i can't rework the faulty part
3rd May 2020, 10:46 AM
Kami
Kami - avatar
0
I don't even know whats the input the test case gives the script, so I don't know what i need to improve.
3rd May 2020, 10:47 AM
Kami
Kami - avatar
0
Ok
3rd May 2020, 10:49 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
0
What console is supposed to show?
3rd May 2020, 10:49 AM
HEUBA BATOMEN Franck Duval
HEUBA BATOMEN Franck Duval - avatar
0
I dont think i understand your question right now, sorry ^^
3rd May 2020, 10:53 AM
Kami
Kami - avatar
0
Anthony Quick great idea, but at the point of writing i didnt even know what RegEx meant :)
5th May 2020, 5:59 AM
Kami
Kami - avatar
0
@ヒトリ Have you considered putting all of the checks in their separate functions #include <iostream> using namespace std; bool chk;// a global variable to be exploited by all bool return functions boolchecks(char ch){ ::chk = 0;//reset the value of global variable to 0 string symbols = "
amp;@%#*!";//string containing the symbols for checking for(int = 0; i < 7; i++) { if(ch == symbols[i]) {::chk = 1; break; } } return ::chk; } bool checkn(char ch) { ::chk = 0; for(int i =0 ; i < 10; i++) {string str= "0123456789";//string containing numbers for comparison if( (ch == str[i]) {::chk = 1; break; } } return ::chk; } int main() { int a=0,b=0,c=0,d=0; string pswrd; getline(cin,pswrd); a=pswrd.length(); for(; b<a; b++){ if(checks(pswrd[b]) == 1){ c++;} if( checkn(pswrd[b]) == 1 ){ d++;} } if(c>=2 && d>=2 && a>=7){ cout << "Strong"; }else { cout << "Weak"; } return 0; } //try this, maybe it helps
2nd Jan 2023, 1:09 PM
Gaurav Kaushik