[csharp] User Login
Viewer
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp3
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- const string USER_IDENTIFICATION = "admin";
- const string USER_SECRET_WORD = "123";
- int trials = 3;
- string entered_username, entered_password;
- bool found = false;
- while(trials > 0 && found == false)
- {
- Console.WriteLine("Enter username: ");
- entered_username = Console.ReadLine();
- if(entered_username != USER_IDENTIFICATION) {
- Console.WriteLine("User name is not correct!");
- trials--;
- Console.WriteLine($"Trials left: {trials}");
- continue;
- }
- Console.WriteLine("Enter password: ");
- entered_password= Console.ReadLine();
- if(entered_password!= USER_SECRET_WORD)
- {
- Console.WriteLine("Password is not correct!");
- trials--;
- Console.WriteLine($"Trials left: {trials}");
- continue;
- }
- found = true;
- }
- if (found == true) {
- Console.WriteLine($"Successfully logged in as: {USER_IDENTIFICATION} in {3 - trials} tries");
- }
- else
- {
- Console.WriteLine("Invalid login!");
- }
- Console.ReadKey();
- }
- }
- }
Editor
You can edit this paste and save as new: