I have used Visual Studio 2019 Community for debugging purpose. But you can use any version of visual studio as per your availability.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | internal class Program { static void Main(string[] args) { string username, password; int ctr = 0; do { Console.Write("Input a username: "); username = Console.ReadLine(); Console.Write("Input a password: "); password = Console.ReadLine(); if (username != "admin" || password != "123456") //increase ctr++; else ctr = 1; } while ((username != "admin" || password != "123456") && (ctr != 3)); //checking if (ctr == 3) Console.WriteLine("\nLogin attemp three or more times. Try later!"); else Console.WriteLine("\nThe password entered successfully!"); Console.ReadLine(); } } |
Output:
1 2 3 4 5 6 7 8 | Input a username: admin Input a password: 123 Input a username: admin Input a password: 123456 The password entered successfully! |