+ 1

Password Rules help!

I cAnt tHE BUG, TEST CASE HIDDEN. static void Main(string[] args) { string password = Console.ReadLine(); char[] notAllowedSymbols = { '!', '#', '

#x27;, '%', '&', '(', ')', '*', ',', '+', '-' }; //your code goes here char[] p = new char[100]; for (int i = 0;i< password.Length; i++) { p[i]= Convert.ToChar(password.Substring(i,1)); } for (int k = 0; k < p.Length; k++) { for (int j = 0; j<notAllowedSymbols.Length; j++) { if(p[k]==notAllowedSymbols[j]) { Console.Write("Invalid"); break; } } } Console.Write(""); }

4th Jan 2021, 8:38 AM
Faris Mohamed
Faris Mohamed - avatar
6 Antworten
+ 8
Faris Mohamed , please give a brief description of the task you want to solve. Thanks!
4th Jan 2021, 12:06 PM
Lothar
Lothar - avatar
+ 5
Faris Mohamed , i think the issue is, that if multiple "not allowed Symbols" are in the password, the output "Invalid" also appears multiple times. This should not be, as stated in the last line of the task description. the current break statement is leaving the inner for loop, but not the outer ones.Try to fix this.
4th Jan 2021, 3:41 PM
Lothar
Lothar - avatar
+ 4
for(int i = 0; i < 10; i++) { if(password.Contains(notAllowedSymbols[i])) { Console.WriteLine("Invalid"); break; } }
28th Jan 2021, 4:00 PM
0shibka
0shibka - avatar
+ 1
now that makes sense! Thank you so much!
4th Jan 2021, 3:47 PM
Faris Mohamed
Faris Mohamed - avatar
0
i know there are other ways. but i am sure this way works too. but i couldnt find the error. just one hidden test case fail.
4th Jan 2021, 11:13 AM
Faris Mohamed
Faris Mohamed - avatar
0
Brief description: All test cases passed except one which is hidden. So i couldn’t find the minor issues in my code or rather the logical flow. Greatly appreciate if someone could identify it. Write a program to take the password as input and output "Invalid", if it contains any disallowed symbols. If the password requirement is satisfied, program shouldn't output anything. Sample Input yl1893!dm$ Sample Output Invalid Hint The message should be output only once regardless of how many disallowed symbols the password contains.
4th Jan 2021, 2:52 PM
Faris Mohamed
Faris Mohamed - avatar