0

Password checker

Does anyone know how to make my if statements reachable? internal class Program { static string password() { Console.WriteLine("Please enter a password:"); string input = Console.ReadLine(); return input; } public static bool PasswordChecker(string input) { // determins if a password is save enough if (input.Length < 6) Console.WriteLine("MUST contain at least 6 letters!"); return false; if (!new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}.Any(s => input.Contains(s))) Console.WriteLine("MUST contain at least one capital letter!"); return false; if (!new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}.Any(s => input.Contains(s))) Console.WriteLine("MUST contain at least one lowercase letter!"); return false; if (!new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" }.Any(s => input.Contains(s))) Console.WriteLine("MUST contain a number!"); return false; if (!new string[] { "!", "'", "§", "

quot;, "%", "&", "/", "(", ")", "=", "?", "*", "#", "+", "-", "_", ".", ",", ";", ":", "`", "´", "^", "°", }.Any(s => input.Contains(s))) Console.WriteLine("MUST contain at least one special character"); return false; return true; } private static void Main(string[] args) { string input = password(); PasswordChecker(input); } }

29th Nov 2022, 12:06 AM
Liam
1 Réponse
+ 1
Use braces around if statements. Otherwise return is out of if block. So fires immediately. You don't actually need returning boolean as you don't caching value so make it void and remove all returns. For anything other, if any, save code and share link. hope it helps..
29th Nov 2022, 7:41 AM
Jayakrishna 🇮🇳