Why is it not working? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why is it not working?

So i am doing the password validator challenge where you need to check if a pass is 7 chars or more long, has 2 or more of special chars and 2 or more numbers. So why isn't it working? Link to code: https://code.sololearn.com/cH5X5rr4Z0Jw/?ref=app

16th Jul 2023, 11:58 PM
Brushymilbil
Brushymilbil - avatar
3 Answers
+ 5
Brushymilbil by using (num) c all character will be convert to number which is wrong class Program     {         static void Main(string[] args)         {        string Password = Console.ReadLine();             char[] chars = {'!', '@', '#', '
#x27;, '%', '&', '*'};             if (Password.Length >= 7 && CheckSpecial(Password, chars) && Hasnums(Password)) {                  Console.WriteLine("Strong");                  return;                }                   Console.WriteLine("Weak");         } private static bool CheckSpecial(string pass,char[] Chars)        {        int am = 0, pm = 0;            foreach (char c in Chars ) {            if (pass.Contains(c))            am += 1;            }            return am > 0;        } private static bool Hasnums(string passw)        {           int amo = 0;            foreach (char c in passw) {                int num = (int)c;                if (num == null) continue;                amo += 1;            }            return amo > 2;        }     }
17th Jul 2023, 3:36 AM
A͢J
A͢J - avatar
+ 4
Brushymilbil Use Char.IsDigit to check numbers private static bool Hasnums(string passw) {           int amo = 0;            foreach (char c in passw) {                if (Char.IsDigit(c))                amo += 1;            }            return amo >= 2;        }     }
17th Jul 2023, 3:40 AM
A͢J
A͢J - avatar
+ 2
Brushymilbil please use the system namespace at beginning of your code. ==> [Code]: using System;
17th Jul 2023, 3:21 AM
Yasin Rahnaward
Yasin Rahnaward - avatar