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
15 Respostas
+ 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)
+ 3
Have you considered RegEx? That would greatly simplify things. đ
+ 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
+ 2
Here, thanks mate
https://code.sololearn.com/cCLiBB3eb4tc/?ref=app
+ 1
Show me your code
+ 1
What expected result?
+ 1
Smith Welder thanks, i was breaking my head at this one
0
I can help you
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
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.
0
Ok
0
What console is supposed to show?
0
I dont think i understand your question right now, sorry ^^
0
Anthony Quick great idea, but at the point of writing i didnt even know what RegEx meant :)
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