Q:

Write a C# Sharp program that takes userid and password as input (type string). After 3 wrong attempts, user will be rejected

0

Write a C# Sharp program that takes userid and password as input (type string). After 3 wrong attempts, user will be rejected

Sample Output:

Input a username: robin                                                                                       
Input a password: sds45                                                                                       
Input a username: john                                                                                        
Input a password: dfgrt                                                                                       
Input a username: doom                                                                                        
Input a password: jkkl

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
public class Exercise3
{
public static void Main()
{
string username, password;
int ctr = 0,dd=0;
       Console.Write("\n\nCheck username and password :\n");
	   Console.Write("N.B. : Defaule username and password is : username and password\n");
       Console.Write("---------------------------------\n"); 
do
{
Console.Write("Input a username: ");
username = Console.ReadLine();
 
Console.Write("Input a password: ");
password = Console.ReadLine();
if( username == "username" && password == "password" )
{
    dd=1;
    ctr=3;
}

else
{
    dd=0;
    ctr++;
}
}
while (( username != "username" || password != "password" )
        && (ctr != 3));
        if (dd == 0)
        {
            Console.Write("\nLogin attemp more than three times. Try later!\n\n");
        }
        else  
        if(dd==1)
        {
            Console.Write("\nPassword entered successfull!\n\n");	}         
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now