Files
Akari.Prototype/Akari.Prototype.Server/Utils/CliUtils.cs
2021-06-07 01:45:39 +02:00

38 lines
965 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Akari.Prototype.Server.Services;
using Spectre.Console;
namespace Akari.Prototype.Server.Utils
{
public static class CliUtils
{
private const int LoginMaxTries = 3;
public static bool Login(IMasterKeyService masterKeyService, IAnsiConsole ansiConsole)
{
string password;
int tries = 0;
do
{
tries++;
ansiConsole.WriteLine();
password = ansiConsole.Prompt(
new TextPrompt<string>("Enter [green]master password[/]")
.PromptStyle("red")
.Secret()
);
ansiConsole.WriteLine();
} while (!masterKeyService.Login(password) && tries < LoginMaxTries);
return masterKeyService.IsLoggedIn;
}
}
}