belongs to collection: All String programs in C# with examples
Write a C# program to check the username and password
I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..
using System; public class Stringexercise { public static void Main() { 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 != "abcd" || password != "1234") ctr++; else ctr = 1; } while ((username != "admin" || password != "123456") && (ctr != 3)); if (ctr == 3) Console.WriteLine("\nLogin attemp three or more times. Try later!"); else Console.WriteLine("\nThe password entered successfully!"); Console.ReadLine(); } }
Result:
Input a username: admin
Input a password: a
Input a password: 123456
The password entered successfully!
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..
Result:
Input a username: admin
Input a password: a
Input a username: admin
Input a password: 123456
The password entered successfully!
need an explanation for this answer? contact us directly to get an explanation for this answer