Password validation cpp | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
24th Aug 2020, 5:52 AM
Mohamad Nourigohar
Mohamad Nourigohar - avatar
7 Answers
+ 4
thank you for your attention
24th Aug 2020, 7:16 AM
Mohamad Nourigohar
Mohamad Nourigohar - avatar
+ 5
#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; } // Mohamad Nourigohar Why are you checking for characters? The password length must be atleast 7 it's written in description.
24th Aug 2020, 6:48 AM
Rohit
+ 5
Minor mistakes committed by Mohamad Nourigohar : 1) The challenge didn't asked for how many capital/small letters does the password have but rather the length of the whole password(including symbols and numeric) must be atleast 7. 2) It is always a good practice to initialize variables when you declare them with 0 or any valid value. 3) [Not mistake but an improvement] Why use those bunch of ifs statement when you can use some syntactic sugar to achieved the same in just few lines. Anyway, the code is perfect and hope you've learnt something new and as always "happy learning" 😇
24th Aug 2020, 6:53 AM
Rohit
+ 2
M̷o̷u̷l̷i̷ 🇮🇳 that doesn't matter as per the challenge descriptions or logic. But yeah, you're right those small typos.
24th Aug 2020, 6:51 AM
Rohit
24th Aug 2020, 5:57 AM
Mohamad Nourigohar
Mohamad Nourigohar - avatar
0
Mohamad Nourigohar I can't find any error in your code.
24th Aug 2020, 6:08 AM
Rohit
- 2
problem is in code coach
24th Aug 2020, 6:22 AM
Mohamad Nourigohar
Mohamad Nourigohar - avatar