Q:

Write a C# program to check the username and password

0

Write a C# program to check the username and password

All Answers

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

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 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

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now