+ 4
Password validation challenge solved
8 Answers
+ 3
Jayakrishna đźđł
Ye.
The problem ask a input to have atleast 2 numbers, 2 symbols and length of at least 7. We have to check if each condition is true by using the "and" operator, it returns "strong" if every condition is true, else "weak".
example:
if len(nums)>=2 and len(syms)>=2 and len(userinput)>=7:
#do smth
+ 5
Emir Yılmaz ,
assuming that the password should use at least *2 digits* **and** *2 special characters*.
in this case:
> when summing the number of digits and of special characters, and checking if the result is >= 4, does not necessarily mean that the
password is *strong*.
> imagine you have *4 digits* and *1 special character*, which is summing up to 5. however the password is not strong.
> the correct way would be to evaluate the number of *digits* and *special characters* each separately.
+ 2
That solves it thanks!
+ 2
Dragon RB yes. I know. That's what am saying don't add to total. Must check individuals.
If input is like @@@1abc Or 1234abc must return weak but saying strong, which leading to fail.
+ 1
Why you are adding
total = count_num+count_sym?
Only 2+2 = 4 case is strong. Other cases (below 2 values) should be "Weak".
Got it ?
+ 1
Emir Yılmaz try using the "isnumeric()" function, and use "isalnum()" function with the "not" operator.
These function makes it even easier to solve..
(isnumeric() will return true if a single character is a number, while isalnum() will return true if a single character is a number OR letter)
0
Hii
0
#include <iostream>
/*
A small converting app by alhaaj
//inter any number
//maximum 7 digit number
sample input - 222
sample output - two hundred and twenty two
*/
int place_value(int n) {
int p = 0;
while (n != 0) {
n /= 10;
p++;
}
return (p);
}
int get_part (int num) {
int n;
switch( place_value(num) ) {
case 2:
n = num % 10;
break;
case 3:
n = num % 100;
break;
case 7:
n = num % 1000000;
break;
default:
n = num % 1000;
}
return (n);
}
void d1(int n);
void d2 (int n);
void d3 (int n);
void d4 (int n);
void d5 (int n); //alhaaj
void d6 (int n);
void d7 (int n);
int main() {
int digit, n;
std::cout<<"Code by alhaaj\n\n";
std::cin >> digit;
std::cout<<"Input >> "<<digit<<"\n"<<"\n";
n = place_value(digit);
std::cout<<"Output >> ";
switch (n) {
case 0:
std::cout<<"zero";
case 1:
d1(digit);
break;