Skip to content

Instantly share code, notes, and snippets.

@Strelok78
Last active April 21, 2025 12:27
Show Gist options
  • Save Strelok78/fabae6884b8dce0bf14e39e03e9c852a to your computer and use it in GitHub Desktop.
Save Strelok78/fabae6884b8dce0bf14e39e03e9c852a to your computer and use it in GitHub Desktop.
Console password check
using System.Diagnostics;
namespace iJuniorPractice;
class Program
{
static void Main(string[] args)
{
const string Password = "abc";
string passwordInput;
string enterPasswordText = "Password: ";
int attemptAllowedCount = 3;
bool isSuccess = false;
for (int i = 0; i < attemptAllowedCount; i++)
{
Console.Write(enterPasswordText);
passwordInput = Console.ReadLine();
if (passwordInput == Password)
{
Console.WriteLine("Coorect!");
isSuccess = true;
break;
}
else
{
int attemptsLeftCount = attemptAllowedCount - i - 1;
Console.WriteLine($"Incorrect password. Attempts left: {attemptsLeftCount}");
}
}
if (isSuccess == false)
{
Console.WriteLine("Error. Authorization blocked! Reboot app.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment