Write a program in C# Sharp to check the username and password

  • برمجة سي شارب
  • برمجة

Write a program in C# Sharp to check the username and password. 
Test Data :
Input a username: uesr
Input a password: pass
Input a username: abcd
Input a password: 1234
Expected Output :

Password entered successfully!

الأجوبة

using System;
public class Exercise16
{
    public static void Main()
    {
       string username, password;
       int ctr = 0;
       Console.Write("\n\nCheck username and password :\n");
	   Console.Write("N.B. : Default user name and password is :abcd and 1234\n");
       Console.Write("------------------------------------------------------\n");         
        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 != "abcd" || password != "1234")  && (ctr != 3));
	 
        if (ctr == 3)
            Console.Write("\nLogin attemp three or more times. Try later!\n\n");
        else   
            Console.Write("\nThe password entered successfully!\n\n");		
    }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...