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

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

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

1 thought on “Write a C# program to check the username and password”

Leave a Comment

x