Last active
April 21, 2025 12:27
-
-
Save Strelok78/fabae6884b8dce0bf14e39e03e9c852a to your computer and use it in GitHub Desktop.
Console password check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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