Write a C# program to check the username and password


Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. public class Stringexercise
  3. {
  4. public static void Main()
  5. {
  6. string username, password;
  7. int ctr = 0;
  8. do
  9. {
  10. Console.Write("Input a username: ");
  11. username = Console.ReadLine();
  12.  
  13. Console.Write("Input a password: ");
  14. password = Console.ReadLine();
  15.  
  16. if (username != "abcd" || password != "1234")
  17. ctr++;
  18. else
  19. ctr = 1;
  20.  
  21. }
  22. while ((username != "admin" || password != "123456") && (ctr != 3));
  23.  
  24. if (ctr == 3)
  25. Console.WriteLine("\nLogin attemp three or more times. Try later!");
  26. else
  27. Console.WriteLine("\nThe password entered successfully!");
  28.  
  29. Console.ReadLine();
  30. }
  31. }

Result

C# language techstudy

     





Related Topics




Popular Posts