0% found this document useful (0 votes)
18 views1 page

C# Login Authentication Example

This C# program implements a simple login system that prompts users for a login and password. It allows up to three attempts for authentication, displaying success or failure messages accordingly. After three failed attempts, the program denies access and suggests contacting support.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

C# Login Authentication Example

This C# program implements a simple login system that prompts users for a login and password. It allows up to three attempts for authentication, displaying success or failure messages accordingly. After three failed attempts, the program denies access and suggests contacting support.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using System;

class Program
{
static void Main()
{
// Correct login and password
string correctLogin = "admin";
string correctPassword = "password123";

int attempts = 0;
bool isAuthenticated = false;

do
{
Console.Write("Enter login: ");
string login = Console.ReadLine();

Console.Write("Enter password: ");


string password = Console.ReadLine();

if (login == correctLogin && password == correctPassword)


{
isAuthenticated = true;
Console.WriteLine("Login successful!");
// Additional actions or permissions can be added here
}
else
{
attempts++;
Console.WriteLine("Login failed. Please try again.");

if (attempts >= 3)
{
Console.WriteLine("You have exceeded the maximum number of
attempts.");
break;
}
}

} while (!isAuthenticated);

if (!isAuthenticated)
{
Console.WriteLine("Access denied. Please contact support for
assistance.");
}
}
}

You might also like