From e9fb109bcc86507791f6fe9c22fca076d4a0cfe5 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 30 Mar 2024 14:36:20 +0100 Subject: [PATCH 1/7] Abstracted Console Interaction in wrapper --- .../Abstractions/ConsoleInteraction.cs | 33 +++++++++++++++++++ PWManager.CLI/Abstractions/PromptHelper.cs | 20 +++++------ PWManager.CLI/ConsoleRunner.cs | 2 +- PWManager.CLI/Controllers/GetController.cs | 6 ++-- PWManager.CLI/Controllers/GroupController.cs | 4 +-- PWManager.CLI/Controllers/InitController.cs | 9 ++--- PWManager.CLI/Controllers/LoginController.cs | 2 +- PWManager.CLI/Controllers/NewController.cs | 2 +- .../Services/AccountTimeoutService.cs | 16 +++++++++ 9 files changed, 72 insertions(+), 22 deletions(-) create mode 100644 PWManager.CLI/Abstractions/ConsoleInteraction.cs create mode 100644 PWManager.CLI/Services/AccountTimeoutService.cs diff --git a/PWManager.CLI/Abstractions/ConsoleInteraction.cs b/PWManager.CLI/Abstractions/ConsoleInteraction.cs new file mode 100644 index 0000000..98913fa --- /dev/null +++ b/PWManager.CLI/Abstractions/ConsoleInteraction.cs @@ -0,0 +1,33 @@ +using Sharprompt; + +namespace PWManager.CLI.Abstractions; + +public static class ConsoleInteraction { + + public static event Action OnConsoleInput; + + public static T Input(string prompt) { + return Prompt.Input(prompt); + } + + public static bool Confirm(string prompt) { + return Prompt.Confirm(prompt); + } + + public static T Select(string message, IEnumerable? items = null, object? defaultValue = null) where T : notnull { + return Prompt.Select(message, items, defaultValue: defaultValue); + } + + public static IEnumerable MultiSelect(string message, IEnumerable? items, IEnumerable? defaultValues) + where T : notnull { + return Prompt.MultiSelect(message, items, defaultValues: defaultValues); + } + + public static string Password(string message) { + return Prompt.Password(message); + } + + public static string? ReadLine() { + return Console.ReadLine(); + } +} \ No newline at end of file diff --git a/PWManager.CLI/Abstractions/PromptHelper.cs b/PWManager.CLI/Abstractions/PromptHelper.cs index d7abb95..a2d04c9 100644 --- a/PWManager.CLI/Abstractions/PromptHelper.cs +++ b/PWManager.CLI/Abstractions/PromptHelper.cs @@ -5,10 +5,10 @@ namespace PWManager.CLI.Abstractions; public static class PromptHelper { public static string GetInput(string prompt) { - var input = Prompt.Input(prompt); + var input = ConsoleInteraction.Input(prompt); while (string.IsNullOrWhiteSpace(input)) { Console.WriteLine("Your input was empty! Try again!"); - input = Prompt.Input(prompt); + input = ConsoleInteraction.Input(prompt); } return input; @@ -16,13 +16,13 @@ public static string GetInput(string prompt) { public static bool InputPassword(Func passwordValidator) { var tryCount = 0; - var pass = Prompt.Password("Enter your password"); + var pass = ConsoleInteraction.Password("Enter your password"); var succ = passwordValidator(pass); while (!succ && tryCount < 3) { ++tryCount; Console.WriteLine($"Password incorrect! Please try again. ({tryCount}/3)"); - pass = Prompt.Password("Enter your password"); + pass = ConsoleInteraction.Password("Enter your password"); succ = passwordValidator(pass); } @@ -40,18 +40,18 @@ public static string InputNewPassword() { } public static string? TryPasswordInput() { - var password = Prompt.Password("Enter your password"); + var password = ConsoleInteraction.Password("Enter your password"); while (string.IsNullOrWhiteSpace(password) || password.Length < 8) { Console.WriteLine("Your password was too short. Please use a password with at least 8 characters!"); - password = Prompt.Password("Enter your password"); + password = ConsoleInteraction.Password("Enter your password"); } - var repeat = Prompt.Password("Repeat your password"); + var repeat = ConsoleInteraction.Password("Repeat your password"); var tryCount = 0; while (!password.Equals(repeat) && tryCount < 3) { ++tryCount; Console.WriteLine($"The repeated password does not match your password! Please try again! ({tryCount}/3)"); - repeat = Prompt.Password("Repeat your password"); + repeat = ConsoleInteraction.Password("Repeat your password"); } return password.Equals(repeat) ? password : null; @@ -95,12 +95,12 @@ public static void PrintColoredText(ConsoleColor color, string text) { } public static bool ConfirmDeletion(string identifier, Func passwordValidator) { - var areYouSure = Prompt.Confirm($"Are you sure you want to delete {identifier}?"); + var areYouSure = ConsoleInteraction.Confirm($"Are you sure you want to delete {identifier}?"); if (!areYouSure) { return false; } - var passwordTest = Prompt.Password("Enter your master password to confirm"); + var passwordTest = ConsoleInteraction.Password("Enter your master password to confirm"); var passwordCorrect = passwordValidator(passwordTest); if (passwordCorrect) { diff --git a/PWManager.CLI/ConsoleRunner.cs b/PWManager.CLI/ConsoleRunner.cs index 6cda578..9c3af28 100644 --- a/PWManager.CLI/ConsoleRunner.cs +++ b/PWManager.CLI/ConsoleRunner.cs @@ -30,7 +30,7 @@ public void Run(string[] args) { var exitCondition = ExecuteCommand(args); while (exitCondition is ExitCondition.CONTINUE) { _environment.WritePrompt(); - var input = Console.ReadLine(); + var input = ConsoleInteraction.ReadLine(); if (input is null) { continue; } diff --git a/PWManager.CLI/Controllers/GetController.cs b/PWManager.CLI/Controllers/GetController.cs index 4c8f53b..9951a95 100644 --- a/PWManager.CLI/Controllers/GetController.cs +++ b/PWManager.CLI/Controllers/GetController.cs @@ -86,17 +86,17 @@ private bool HandleDeletion(string identifier) { } private bool ConfirmRegeneration(string identifier) { - return Prompt.Confirm($"Are you sure you want to update the password of {identifier}?"); + return ConsoleInteraction.Confirm($"Are you sure you want to update the password of {identifier}?"); } private AccountAction GetAccountAction() { - return Prompt.Select("Select an Action"); + return ConsoleInteraction.Select("Select an Action"); } private string? GetAccountSelection() { var names = _accountService.GetCurrentAccountNames(); if (names.Any()) { - return Prompt.Select("Search an Account", names); + return ConsoleInteraction.Select("Search an Account", names); } PromptHelper.PrintColoredText(ConsoleColor.Red, "There are no accounts in this group!"); return null; diff --git a/PWManager.CLI/Controllers/GroupController.cs b/PWManager.CLI/Controllers/GroupController.cs index 0d61e34..95d61cf 100644 --- a/PWManager.CLI/Controllers/GroupController.cs +++ b/PWManager.CLI/Controllers/GroupController.cs @@ -34,7 +34,7 @@ public GroupController(IGroupService groupService, IUserEnvironment userEnv, ILo } public ExitCondition Handle(string[] args) { // TODO: eventuell refactoring - var option = Prompt.Select("Select an action", new[] { newGroup, switchGroup, listAllGroups, deleteGroup, exit }); + var option = ConsoleInteraction.Select("Select an action", new[] { newGroup, switchGroup, listAllGroups, deleteGroup, exit }); if (option.Equals(exit)) { return ExitCondition.CONTINUE; @@ -68,7 +68,7 @@ private void SwitchGroup(List groups) { if (!groups.Any()) { throw new UserFeedbackException("There are no groups in your database. Something is really wrong!"); } - var groupidentifier = Prompt.Select("To which group do you want to switch to", groups); + var groupidentifier = ConsoleInteraction.Select("To which group do you want to switch to", groups); _groupService.SwitchGroup(groupidentifier); } diff --git a/PWManager.CLI/Controllers/InitController.cs b/PWManager.CLI/Controllers/InitController.cs index a9d5ce8..37d60bf 100644 --- a/PWManager.CLI/Controllers/InitController.cs +++ b/PWManager.CLI/Controllers/InitController.cs @@ -22,18 +22,19 @@ public InitController(IDatabaseInitializerService dbInit) { } public ExitCondition Handle(string[] args) { - var path = Prompt.Input("Where do you want to create your database file?"); + var path = ConsoleInteraction.Input("Where do you want to create your database file?"); while(!Path.Exists(path)) { Console.WriteLine("The given path does not exist."); - path = Prompt.Input("Where do you want to create your database file?"); + path = ConsoleInteraction.Input("Where do you want to create your database file?"); } _dbInit.CheckIfDataBaseExistsOnPath(path); - var name = Prompt.Input("What's your desired user name?"); + var name = ConsoleInteraction.Input("What's your desired user name?"); + while (name.Length <= 1 || !Regex.IsMatch(name, @"^[a-zA-Z]+$")) { Console.WriteLine("Invalid name! It mus be longer than 1 character and must include only letters!"); - name = Prompt.Input("What's your desired user name?"); + name = ConsoleInteraction.Input("What's your desired user name?"); } var password = PromptHelper.InputNewPassword(); diff --git a/PWManager.CLI/Controllers/LoginController.cs b/PWManager.CLI/Controllers/LoginController.cs index 53919fc..661c99e 100644 --- a/PWManager.CLI/Controllers/LoginController.cs +++ b/PWManager.CLI/Controllers/LoginController.cs @@ -69,7 +69,7 @@ public ExitCondition Handle(string[] args) { } public virtual string AskForInput(string prompt) { - return Prompt.Input(prompt); + return ConsoleInteraction.Input(prompt); } } } diff --git a/PWManager.CLI/Controllers/NewController.cs b/PWManager.CLI/Controllers/NewController.cs index 3c8e6f9..512de24 100644 --- a/PWManager.CLI/Controllers/NewController.cs +++ b/PWManager.CLI/Controllers/NewController.cs @@ -24,7 +24,7 @@ public ExitCondition Handle(string[] args) { var identifier = PromptHelper.GetInput("What's the name of the website?"); var loginName = PromptHelper.GetInput("What's your name or email for the login?"); - var genPassword = Prompt.Confirm("Do you want to generate a random password?"); + var genPassword = ConsoleInteraction.Confirm("Do you want to generate a random password?"); string password; if (genPassword) { password = _passwordGeneratorService.GeneratePassword(); diff --git a/PWManager.CLI/Services/AccountTimeoutService.cs b/PWManager.CLI/Services/AccountTimeoutService.cs new file mode 100644 index 0000000..a805d98 --- /dev/null +++ b/PWManager.CLI/Services/AccountTimeoutService.cs @@ -0,0 +1,16 @@ +using PWManager.CLI.Abstractions; + +namespace PWManager.CLI.Services; + +public class AccountTimeoutService { + + public AccountTimeoutService() { + ConsoleInteraction.OnConsoleInput += OnConsoleInput; + } + + private void + + private void OnConsoleInput() { + + } +} \ No newline at end of file From 99591d13d5eb7496ebe9fe56bbbb67ae15003cbb Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 30 Mar 2024 15:21:27 +0100 Subject: [PATCH 2/7] Added Account Timeout settings to settgins --- .../Context/IUserEnvironment.cs | 2 ++ .../Services/Interfaces/ISettingsService.cs | 3 +- .../Services/SettingsService.cs | 24 ++++++++----- .../Abstractions/ConsoleInteraction.cs | 2 +- PWManager.CLI/Abstractions/PromptHelper.cs | 11 ++++++ .../Controllers/SettingsController.cs | 36 +++++++++++-------- PWManager.CLI/Enums/SettingsActions.cs | 2 ++ PWManager.CLI/Environment/CliEnvironment.cs | 2 ++ PWManager.Data/Models/SettingsModel.cs | 3 +- .../Repositories/SettingsRepository.cs | 5 +-- PWManager.Data/Services/LoginService.cs | 1 + PWManager.Domain/Entities/Settings.cs | 10 +++--- .../ValueObjects/ClipboardTimeoutSetting.cs | 13 ++++--- 13 files changed, 77 insertions(+), 37 deletions(-) diff --git a/PWManager.Application/Context/IUserEnvironment.cs b/PWManager.Application/Context/IUserEnvironment.cs index 8300a1c..47c7b8f 100644 --- a/PWManager.Application/Context/IUserEnvironment.cs +++ b/PWManager.Application/Context/IUserEnvironment.cs @@ -6,4 +6,6 @@ public interface IUserEnvironment { public User? CurrentUser { get; set; } public Group? CurrentGroup { get; set; } + + public Settings? UserSettings { get; set; } } \ No newline at end of file diff --git a/PWManager.Application/Services/Interfaces/ISettingsService.cs b/PWManager.Application/Services/Interfaces/ISettingsService.cs index c83f301..ac6e61c 100644 --- a/PWManager.Application/Services/Interfaces/ISettingsService.cs +++ b/PWManager.Application/Services/Interfaces/ISettingsService.cs @@ -6,7 +6,8 @@ namespace PWManager.Application.Services.Interfaces; public interface ISettingsService { void ChangePasswordGenerationCriteria(PasswordGeneratorCriteria generatorCriteria); - void ChangeClipboardTimeoutSetting(ClipboardTimeoutSetting clipboardTimeoutSetting); + void ChangeClipboardTimeoutSetting(TimeSpan timeout); + void ChangeAccountTimeoutSetting(TimeSpan timeout); void ChangeMainGroupSetting(MainGroupSetting mainGroupSetting); Settings GetSettings(); } diff --git a/PWManager.Application/Services/SettingsService.cs b/PWManager.Application/Services/SettingsService.cs index 1be4419..c9ddf22 100644 --- a/PWManager.Application/Services/SettingsService.cs +++ b/PWManager.Application/Services/SettingsService.cs @@ -9,30 +9,38 @@ namespace PWManager.Application.Services; public class SettingsService : ISettingsService { private readonly ISettingsRepository _settingsRepository; - - public SettingsService(ISettingsRepository settingsRepository) { + private readonly IUserEnvironment _userEnv; + + public SettingsService(ISettingsRepository settingsRepository, IUserEnvironment userEnv) { _settingsRepository = settingsRepository; + _userEnv = userEnv; } - public void ChangeClipboardTimeoutSetting(ClipboardTimeoutSetting clipboardTimeout) { - var settings = _settingsRepository.GetSettings(); - settings.ClipboardTimeout = clipboardTimeout; + public void ChangeClipboardTimeoutSetting(TimeSpan timeout) { + var settings = GetSettings(); + settings.Timeout = new TimeoutSettings(timeout, settings.Timeout.AccountTimeOutDuration); + _settingsRepository.UpdateSettings(settings); + } + + public void ChangeAccountTimeoutSetting(TimeSpan timeout) { + var settings = GetSettings(); + settings.Timeout = new TimeoutSettings(settings.Timeout.ClipboardTimeOutDuration, timeout); _settingsRepository.UpdateSettings(settings); } public void ChangeMainGroupSetting(MainGroupSetting mainGroup) { - var settings = _settingsRepository.GetSettings(); + var settings = GetSettings(); settings.MainGroup = mainGroup; _settingsRepository.UpdateSettings(settings); } public void ChangePasswordGenerationCriteria(PasswordGeneratorCriteria generatorCriteria) { - var settings = _settingsRepository.GetSettings(); + var settings = GetSettings(); settings.PwGenCriteria = generatorCriteria; _settingsRepository.UpdateSettings(settings); } public Settings GetSettings() { - return _settingsRepository.GetSettings(); + return _userEnv.UserSettings ??= _settingsRepository.GetSettings(); } } \ No newline at end of file diff --git a/PWManager.CLI/Abstractions/ConsoleInteraction.cs b/PWManager.CLI/Abstractions/ConsoleInteraction.cs index 98913fa..56e3f06 100644 --- a/PWManager.CLI/Abstractions/ConsoleInteraction.cs +++ b/PWManager.CLI/Abstractions/ConsoleInteraction.cs @@ -18,7 +18,7 @@ public static T Select(string message, IEnumerable? items = null, object? return Prompt.Select(message, items, defaultValue: defaultValue); } - public static IEnumerable MultiSelect(string message, IEnumerable? items, IEnumerable? defaultValues) + public static IEnumerable MultiSelect(string message, IEnumerable? items = null, IEnumerable? defaultValues = null) where T : notnull { return Prompt.MultiSelect(message, items, defaultValues: defaultValues); } diff --git a/PWManager.CLI/Abstractions/PromptHelper.cs b/PWManager.CLI/Abstractions/PromptHelper.cs index a2d04c9..d76c0bb 100644 --- a/PWManager.CLI/Abstractions/PromptHelper.cs +++ b/PWManager.CLI/Abstractions/PromptHelper.cs @@ -13,6 +13,17 @@ public static string GetInput(string prompt) { return input; } + + public static int GetInputGreaterThan(string message, int greaterThan) { + var val = ConsoleInteraction.Input(message); + + while(val <= greaterThan) { + PromptHelper.PrintColoredText(ConsoleColor.Red, $"Value cannot be less than {greaterThan + 1}"); + val = ConsoleInteraction.Input(message); + } + + return val; + } public static bool InputPassword(Func passwordValidator) { var tryCount = 0; diff --git a/PWManager.CLI/Controllers/SettingsController.cs b/PWManager.CLI/Controllers/SettingsController.cs index 721912f..6c684f2 100644 --- a/PWManager.CLI/Controllers/SettingsController.cs +++ b/PWManager.CLI/Controllers/SettingsController.cs @@ -40,6 +40,7 @@ private bool ExecuteAction(SettingsActions action) { SettingsActions.CURRENT_SETTINGS => ShowCurrentSettings(), SettingsActions.MAIN_GROUP => HandleChangeMainGroup(), SettingsActions.CLIPBOARD_TIMEOUT => HandleChangeClipboardTimeout(), + SettingsActions.ACCOUNT_TIMEOUT => HandleChangeAccountTimeout(), SettingsActions.PASSWORD_CRITERIA => HandleChangePwGenCriteria(), SettingsActions.RETURN => true, _ => false @@ -52,7 +53,7 @@ private bool HandleChangeMainGroup() { throw new UserFeedbackException("There are no groups in your database. Something is really wrong!"); } - var selectedgroup = Prompt.Select("Which group will be your new main group?", groups); + var selectedgroup = ConsoleInteraction.Select("Which group will be your new main group?", groups); var newMainGroup = new MainGroupSetting(selectedgroup); _settingsService.ChangeMainGroupSetting(newMainGroup); @@ -61,20 +62,22 @@ private bool HandleChangeMainGroup() { } private bool HandleChangeClipboardTimeout() { - var seconds = Prompt.Input("After how many seconds shoud your Clipboard be cleared?"); - - while(seconds <= 0) { - PromptHelper.PrintColoredText(ConsoleColor.Red, "Timeout cannot be less or equal than 0"); - seconds = Prompt.Input("After how many seconds shoud your Clipboard be cleared?"); - } - + var seconds = PromptHelper.GetInputGreaterThan("After how many seconds should your Clipboard be cleared?", 0); var timeout = new TimeSpan(TimeSpan.TicksPerSecond * seconds); - _settingsService.ChangeClipboardTimeoutSetting(new ClipboardTimeoutSetting(timeout)); + _settingsService.ChangeClipboardTimeoutSetting(timeout); - PromptHelper.PrintColoredText(ConsoleColor.Green, $"Timeout is now set to {seconds} seconds"); + PromptHelper.PrintColoredText(ConsoleColor.Green, $"Clipboard Timeout is now set to {seconds} seconds"); return true; } + private bool HandleChangeAccountTimeout() { + var minutes = PromptHelper.GetInputGreaterThan("After how many minutes of inactivity should the application quit?", 0); + var timeout = new TimeSpan(TimeSpan.TicksPerSecond * minutes * 60); + _settingsService.ChangeAccountTimeoutSetting(timeout); + PromptHelper.PrintColoredText(ConsoleColor.Green, $"Account Timeout is now set to {minutes} minutes"); + return true; + } + private bool HandleChangePwGenCriteria() { var pwGenCriteria = CreatePwGenerationCriteria(); if(pwGenCriteria is null) { @@ -92,7 +95,7 @@ private bool HandleChangePwGenCriteria() { List defaults = getDefaults(); - var selects = Prompt.MultiSelect("Include", defaultValues: defaults); + var selects = ConsoleInteraction.MultiSelect("Include", defaultValues: defaults); var includeLowerCase = selects.Contains(PasswordCriteriaOptions.LOWER_CASE); var includeUpperCase = selects.Contains(PasswordCriteriaOptions.UPPER_CASE); ; @@ -101,8 +104,8 @@ private bool HandleChangePwGenCriteria() { var includeBrackets = selects.Contains(PasswordCriteriaOptions.BRACKETS); ; var includeSpaces = selects.Contains(PasswordCriteriaOptions.SPACE); ; - var minLength = Prompt.Input("What's the minimum length your passwoard should have?"); - var maxLength = Prompt.Input("What's the maximum length your passwoard should have?"); + var minLength = ConsoleInteraction.Input("What's the minimum length your password should have?"); + var maxLength = ConsoleInteraction.Input("What's the maximum length your password should have?"); try { var pwGenCriteria = new PasswordGeneratorCriteria(includeLowerCase, includeUpperCase, includeNumeric, includeSpecial, includeBrackets, @@ -143,7 +146,12 @@ public bool ShowCurrentSettings() { Console.Write("Clipboard Timeout: "); Console.ForegroundColor = ConsoleColor.Cyan; - Console.WriteLine(settings.ClipboardTimeout.TimeOutDuration.TotalSeconds + " s"); + Console.WriteLine(settings.Timeout.ClipboardTimeOutDuration.TotalSeconds + " s"); + Console.ForegroundColor = defaultcolor; + + Console.Write("Account Timeout: "); + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine(settings.Timeout.AccountTimeOutDuration.TotalMinutes + " m"); Console.ForegroundColor = defaultcolor; Console.WriteLine("-----------------------------"); diff --git a/PWManager.CLI/Enums/SettingsActions.cs b/PWManager.CLI/Enums/SettingsActions.cs index c8a81ed..f9352ed 100644 --- a/PWManager.CLI/Enums/SettingsActions.cs +++ b/PWManager.CLI/Enums/SettingsActions.cs @@ -8,6 +8,8 @@ public enum SettingsActions { MAIN_GROUP, [Display(Name = "Change Clipboard Timeout")] CLIPBOARD_TIMEOUT, + [Display(Name = "Change Account Timeout")] + ACCOUNT_TIMEOUT, [Display(Name = "Change Password Criterias")] PASSWORD_CRITERIA, [Display(Name = "Go Back")] diff --git a/PWManager.CLI/Environment/CliEnvironment.cs b/PWManager.CLI/Environment/CliEnvironment.cs index 72ac4a4..4dadaf7 100644 --- a/PWManager.CLI/Environment/CliEnvironment.cs +++ b/PWManager.CLI/Environment/CliEnvironment.cs @@ -26,5 +26,7 @@ public void WritePrompt() { public Group? CurrentGroup { get; set; } + public Settings? UserSettings { get; set; } + public string? EncryptionKey { get; set; } } \ No newline at end of file diff --git a/PWManager.Data/Models/SettingsModel.cs b/PWManager.Data/Models/SettingsModel.cs index c7d7fa3..03386a0 100644 --- a/PWManager.Data/Models/SettingsModel.cs +++ b/PWManager.Data/Models/SettingsModel.cs @@ -32,7 +32,8 @@ internal class SettingsModel { [Required] public int MaxLength { get; set; } = 10; - public TimeSpan TimeOutDuration { get; set; } + public TimeSpan ClipboardTimeOutDuration { get; set; } + public TimeSpan AccountTimeOutDuration { get; set; } [Required] public string MainGroupIdentifier { get; set; } = "main"; diff --git a/PWManager.Data/Repositories/SettingsRepository.cs b/PWManager.Data/Repositories/SettingsRepository.cs index cb84cc7..896eda9 100644 --- a/PWManager.Data/Repositories/SettingsRepository.cs +++ b/PWManager.Data/Repositories/SettingsRepository.cs @@ -69,7 +69,7 @@ private Settings SettingsModelToEntity(SettingsModel e) { e.UserId, new PasswordGeneratorCriteria(e.IncludeLowerCase, e.IncludeUpperCase, e.IncludeNumeric, e.IncludeSpecial, e.IncludeBrackets, e.IncludeSpaces, e.MinLength, e.MaxLength), - new ClipboardTimeoutSetting(e.TimeOutDuration), + new TimeoutSettings(e.ClipboardTimeOutDuration, e.AccountTimeOutDuration), new MainGroupSetting(_cryptService.Decrypt(e.MainGroupIdentifier)) ); } @@ -90,7 +90,8 @@ private SettingsModel SettingsEntityToModel(Settings e) { settingsModel.IncludeSpecial = e.PwGenCriteria.IncludeSpecial; settingsModel.MinLength = e.PwGenCriteria.MinLength; settingsModel.MaxLength = e.PwGenCriteria.MaxLength; - settingsModel.TimeOutDuration = e.ClipboardTimeout.TimeOutDuration; + settingsModel.ClipboardTimeOutDuration = e.Timeout.ClipboardTimeOutDuration; + settingsModel.AccountTimeOutDuration = e.Timeout.AccountTimeOutDuration; settingsModel.MainGroupIdentifier = _cryptService.Encrypt(e.MainGroup.MainGroupIdentifier); return settingsModel; diff --git a/PWManager.Data/Services/LoginService.cs b/PWManager.Data/Services/LoginService.cs index 285136c..3ea38ea 100644 --- a/PWManager.Data/Services/LoginService.cs +++ b/PWManager.Data/Services/LoginService.cs @@ -54,6 +54,7 @@ private void SetSessionParameters(User user, string password) { _cliEnv.RunningSession = true; _userEnv.CurrentGroup = _groupRepository.GetGroup(mainGroup.MainGroupIdentifier); + _userEnv.UserSettings = _settingsRepository.GetSettings(); } public bool CheckPassword(string username, string password) { diff --git a/PWManager.Domain/Entities/Settings.cs b/PWManager.Domain/Entities/Settings.cs index 3edd74f..30695e1 100644 --- a/PWManager.Domain/Entities/Settings.cs +++ b/PWManager.Domain/Entities/Settings.cs @@ -6,19 +6,19 @@ namespace PWManager.Domain.Entities { public class Settings : Entity { public string UserId { get; set; } public PasswordGeneratorCriteria PwGenCriteria { get; set; } - public ClipboardTimeoutSetting ClipboardTimeout { get; set; } + public TimeoutSettings Timeout { get; set; } public MainGroupSetting MainGroup { get; set; } - public Settings(string userId, PasswordGeneratorCriteria pwGenCriteria, ClipboardTimeoutSetting clipboardTimeout, MainGroupSetting mainGroup) : base(){ + public Settings(string userId, PasswordGeneratorCriteria pwGenCriteria, TimeoutSettings timeout, MainGroupSetting mainGroup) : base(){ UserId = userId; PwGenCriteria = pwGenCriteria; - ClipboardTimeout = clipboardTimeout; + Timeout = timeout; MainGroup = mainGroup; } - public Settings(string id, DateTimeOffset created, DateTimeOffset updated, string userId, PasswordGeneratorCriteria pwGenCriteria, ClipboardTimeoutSetting clipboardTimeout, MainGroupSetting mainGroup) : base(id, created, updated) { + public Settings(string id, DateTimeOffset created, DateTimeOffset updated, string userId, PasswordGeneratorCriteria pwGenCriteria, TimeoutSettings timeout, MainGroupSetting mainGroup) : base(id, created, updated) { UserId = userId; PwGenCriteria = pwGenCriteria; - ClipboardTimeout = clipboardTimeout; + Timeout = timeout; MainGroup = mainGroup; } } diff --git a/PWManager.Domain/ValueObjects/ClipboardTimeoutSetting.cs b/PWManager.Domain/ValueObjects/ClipboardTimeoutSetting.cs index 4e630a9..00759df 100644 --- a/PWManager.Domain/ValueObjects/ClipboardTimeoutSetting.cs +++ b/PWManager.Domain/ValueObjects/ClipboardTimeoutSetting.cs @@ -2,16 +2,19 @@ using PWManager.Domain.Common; namespace PWManager.Domain.ValueObjects { - public class ClipboardTimeoutSetting : ValueObject { + public class TimeoutSettings : ValueObject { - public TimeSpan TimeOutDuration { get; } + public TimeSpan ClipboardTimeOutDuration { get; } + public TimeSpan AccountTimeOutDuration { get; } - public ClipboardTimeoutSetting(TimeSpan timeOutDuration) { - TimeOutDuration = timeOutDuration; + public TimeoutSettings(TimeSpan clipboardTimeOutDuration, TimeSpan accountTimeOutDuration) { + ClipboardTimeOutDuration = clipboardTimeOutDuration; + AccountTimeOutDuration = accountTimeOutDuration; } protected override IEnumerable GetEqualityComponents() { - yield return TimeOutDuration; + yield return ClipboardTimeOutDuration; + yield return AccountTimeOutDuration; } } } From a8b2a06606728c7e26a4484a90ec884f883c771e Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 30 Mar 2024 17:15:59 +0100 Subject: [PATCH 3/7] Added Account Timeout --- .../Context/ICancelEnvironment.cs | 5 ++ .../Services/AccountTimeoutService.cs | 58 +++++++++++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 PWManager.Application/Context/ICancelEnvironment.cs diff --git a/PWManager.Application/Context/ICancelEnvironment.cs b/PWManager.Application/Context/ICancelEnvironment.cs new file mode 100644 index 0000000..3cfe99f --- /dev/null +++ b/PWManager.Application/Context/ICancelEnvironment.cs @@ -0,0 +1,5 @@ +namespace PWManager.Application.Context; + +public class ICancelEnvironment { + +} \ No newline at end of file diff --git a/PWManager.CLI/Services/AccountTimeoutService.cs b/PWManager.CLI/Services/AccountTimeoutService.cs index a805d98..e1f9040 100644 --- a/PWManager.CLI/Services/AccountTimeoutService.cs +++ b/PWManager.CLI/Services/AccountTimeoutService.cs @@ -1,16 +1,66 @@ -using PWManager.CLI.Abstractions; +using PWManager.Application.Context; +using PWManager.CLI.Abstractions; namespace PWManager.CLI.Services; public class AccountTimeoutService { + + private readonly IUserEnvironment _userEnv; + private readonly ICancelEnvironment _cancelEnv; + + private DateTime _lastKeyInput; + + private Task? _monitoringTask; - public AccountTimeoutService() { + public AccountTimeoutService(IUserEnvironment userEnv, ICancelEnvironment cancelEnv) { + _userEnv = userEnv; + _cancelEnv = cancelEnv; ConsoleInteraction.OnConsoleInput += OnConsoleInput; } - private void + public void StartMonitoring(CancellationToken cancelToken) { + if (_monitoringTask is not null) { + return; + } + _lastKeyInput = DateTime.Now; + + _monitoringTask = TimeoutTask(cancelToken); + } + + + private async Task TimeoutTask(CancellationToken cancelToken) { + try { + while (DateTime.Now.Subtract(_lastKeyInput) <= GetAccountTimeoutSpan() || !_cancelEnv.CancelableState) { + cancelToken.ThrowIfCancellationRequested(); + var timeoutSeconds = GetAccountTimeoutSpan().Seconds; + + var checkFrequencySeconds = MinMaxBetween(timeoutSeconds / 4, 15, 60); + + await Task.Delay(checkFrequencySeconds * 1000, cancelToken); + cancelToken.ThrowIfCancellationRequested(); + } + } + catch (OperationCanceledException) { + return; + } + ConsoleInteraction.ResetConsole(); + PromptHelper.PrintColoredText(ConsoleColor.Magenta, $"You were logged out due to inactivity for {GetAccountTimeoutSpan().Minutes} minutes"); + System.Environment.Exit(0); + } + + private TimeSpan GetAccountTimeoutSpan() { + if (_userEnv.UserSettings is null) { + return TimeSpan.FromMinutes(2); + } + return _userEnv.UserSettings.Timeout.AccountTimeOutDuration; + } + + private int MinMaxBetween(int val, int min, int max) { + return Math.Max(Math.Min(val, max), min); + } private void OnConsoleInput() { - + _lastKeyInput = DateTime.Now; } + } \ No newline at end of file From b49202f7cc6d3c6447e0b478047c3c29c1af1cdc Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 30 Mar 2024 17:16:12 +0100 Subject: [PATCH 4/7] Added cancel state --- .../Context/ICancelEnvironment.cs | 4 +- .../Abstractions/ConsoleInteraction.cs | 37 ++++++++++++++++--- PWManager.CLI/ConsoleRunner.cs | 11 +++++- PWManager.CLI/Environment/CliEnvironment.cs | 4 +- PWManager.CLI/Program.cs | 16 +++++++- 5 files changed, 60 insertions(+), 12 deletions(-) diff --git a/PWManager.Application/Context/ICancelEnvironment.cs b/PWManager.Application/Context/ICancelEnvironment.cs index 3cfe99f..a176ba9 100644 --- a/PWManager.Application/Context/ICancelEnvironment.cs +++ b/PWManager.Application/Context/ICancelEnvironment.cs @@ -1,5 +1,5 @@ namespace PWManager.Application.Context; -public class ICancelEnvironment { - +public interface ICancelEnvironment { + bool CancelableState { get; set; } } \ No newline at end of file diff --git a/PWManager.CLI/Abstractions/ConsoleInteraction.cs b/PWManager.CLI/Abstractions/ConsoleInteraction.cs index 56e3f06..49bd570 100644 --- a/PWManager.CLI/Abstractions/ConsoleInteraction.cs +++ b/PWManager.CLI/Abstractions/ConsoleInteraction.cs @@ -7,27 +7,52 @@ public static class ConsoleInteraction { public static event Action OnConsoleInput; public static T Input(string prompt) { - return Prompt.Input(prompt); + OnConsoleInput(); + var res = Prompt.Input(prompt); + OnConsoleInput(); + return res; } public static bool Confirm(string prompt) { - return Prompt.Confirm(prompt); + OnConsoleInput(); + var res = Prompt.Confirm(prompt); + OnConsoleInput(); + return res; } public static T Select(string message, IEnumerable? items = null, object? defaultValue = null) where T : notnull { - return Prompt.Select(message, items, defaultValue: defaultValue); + OnConsoleInput(); + var res = Prompt.Select(message, items, defaultValue: defaultValue); + OnConsoleInput(); + return res; } public static IEnumerable MultiSelect(string message, IEnumerable? items = null, IEnumerable? defaultValues = null) where T : notnull { - return Prompt.MultiSelect(message, items, defaultValues: defaultValues); + OnConsoleInput(); + var res = Prompt.MultiSelect(message, items, defaultValues: defaultValues); + OnConsoleInput(); + return res; } public static string Password(string message) { - return Prompt.Password(message); + OnConsoleInput(); + var res = Prompt.Password(message); + OnConsoleInput(); + return res; } public static string? ReadLine() { - return Console.ReadLine(); + OnConsoleInput(); + var res = Console.ReadLine(); + OnConsoleInput(); + return res; + } + + public static void ResetConsole() { + Console.CursorVisible = true; + Console.ResetColor(); + Console.SetCursorPosition(0, Console.CursorTop); + Console.WriteLine(); } } \ No newline at end of file diff --git a/PWManager.CLI/ConsoleRunner.cs b/PWManager.CLI/ConsoleRunner.cs index 9c3af28..ce988de 100644 --- a/PWManager.CLI/ConsoleRunner.cs +++ b/PWManager.CLI/ConsoleRunner.cs @@ -16,12 +16,14 @@ internal class ConsoleRunner : IRunner { private readonly IServiceProvider _provider; private readonly ICliEnvironment _environment; private readonly IDebugEnvironment _debugInfo; + private readonly ICancelEnvironment _cancelEnvironment; private readonly CommandParser _commandParser; - public ConsoleRunner(IServiceProvider provider, ICliEnvironment environment, IDebugEnvironment debugInfo) { + public ConsoleRunner(IServiceProvider provider, ICliEnvironment environment, IDebugEnvironment debugInfo, ICancelEnvironment cancelEnvironment) { _provider = provider; _environment = environment; _debugInfo = debugInfo; + _cancelEnvironment = cancelEnvironment; _commandParser = new CommandParser(); } @@ -62,7 +64,9 @@ private ExitCondition ExecuteCommand(string input) { return ExecuteCommand(_commandParser.ParseCommandWithArguments(input).ToArray()); } private ExitCondition ExecuteCommand(string[] args) { + _cancelEnvironment.CancelableState = false; if (args.Length <= 0 && _environment.RunningSession) { + _cancelEnvironment.CancelableState = true; return ExitCondition.CONTINUE; } var cmd = args.Length <= 0 ? AvailableCommands.HELP : _commandParser.ParseCommand(args[0]); @@ -73,7 +77,10 @@ private ExitCondition ExecuteCommand(string[] args) { var controller = (IController) _provider.GetRequiredService(controllerType); var commandArgs = args.Length <= 1 ? Array.Empty() : args[1..]; - return controller.Handle(commandArgs); + + var exit = controller.Handle(commandArgs); + _cancelEnvironment.CancelableState = true; + return exit; } public void MapCommand(AvailableCommands command) { diff --git a/PWManager.CLI/Environment/CliEnvironment.cs b/PWManager.CLI/Environment/CliEnvironment.cs index 4dadaf7..823d625 100644 --- a/PWManager.CLI/Environment/CliEnvironment.cs +++ b/PWManager.CLI/Environment/CliEnvironment.cs @@ -3,7 +3,7 @@ namespace PWManager.CLI.Environment; -public class CliEnvironment : ICliEnvironment, IDebugEnvironment, IUserEnvironment, ICryptEnvironment { +public class CliEnvironment : ICliEnvironment, IDebugEnvironment, IUserEnvironment, ICryptEnvironment, ICancelEnvironment { public bool IsDevelopmentMode { get; init; } = true; @@ -29,4 +29,6 @@ public void WritePrompt() { public Settings? UserSettings { get; set; } public string? EncryptionKey { get; set; } + + public bool CancelableState { get; set; } } \ No newline at end of file diff --git a/PWManager.CLI/Program.cs b/PWManager.CLI/Program.cs index ca67be3..4afa452 100644 --- a/PWManager.CLI/Program.cs +++ b/PWManager.CLI/Program.cs @@ -2,9 +2,11 @@ using PWManager.Application; using PWManager.Application.Context; using PWManager.CLI; +using PWManager.CLI.Abstractions; using PWManager.CLI.Environment; using PWManager.CLI.ExtensionMethods; using PWManager.CLI.Interfaces; +using PWManager.CLI.Services; using PWManager.Data; using Sharprompt; @@ -23,6 +25,10 @@ services.AddSingleton(environment); services.AddSingleton(environment); services.AddSingleton(environment); +services.AddSingleton(environment); + +// Create Observer for key inputs to kick client for inactivity +var accountTimeOutObserver = new AccountTimeoutService(environment, environment); // Add all services to DI services.AddSingleton(); @@ -42,4 +48,12 @@ // Map Controller routes ((ConsoleRunner)runner).MapControllers(); -runner.Run(args); \ No newline at end of file +using var cancelTokenSource = new CancellationTokenSource(); +var cancelToken = cancelTokenSource.Token; +accountTimeOutObserver.StartMonitoring(cancelToken); + +try { + runner.Run(args); +} finally { + ConsoleInteraction.ResetConsole(); +} From 91fbe87b6d583038a5ff02ac41f713ada0ed783a Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 30 Mar 2024 17:53:51 +0100 Subject: [PATCH 5/7] Added Clipboard timeout --- .../Services/Interfaces/IClipboard.cs | 2 + PWManager.CLI/Program.cs | 7 +++ .../Services/ClipboardTimeoutService.cs | 56 +++++++++++++++++++ PWManager.Data/DependencyInjection.cs | 2 +- PWManager.Data/System/Clipboard.cs | 4 ++ 5 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 PWManager.CLI/Services/ClipboardTimeoutService.cs diff --git a/PWManager.Application/Services/Interfaces/IClipboard.cs b/PWManager.Application/Services/Interfaces/IClipboard.cs index 335d16d..d2ee573 100644 --- a/PWManager.Application/Services/Interfaces/IClipboard.cs +++ b/PWManager.Application/Services/Interfaces/IClipboard.cs @@ -2,6 +2,8 @@ public interface IClipboard { + event Action OnClipboardUpdated; + void WriteClipboard(string val); void ClearClipboard(); diff --git a/PWManager.CLI/Program.cs b/PWManager.CLI/Program.cs index 4afa452..3fdea8a 100644 --- a/PWManager.CLI/Program.cs +++ b/PWManager.CLI/Program.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.DependencyInjection; using PWManager.Application; using PWManager.Application.Context; +using PWManager.Application.Services.Interfaces; using PWManager.CLI; using PWManager.CLI.Abstractions; using PWManager.CLI.Environment; @@ -48,12 +49,18 @@ // Map Controller routes ((ConsoleRunner)runner).MapControllers(); +#region Hosted Services using var cancelTokenSource = new CancellationTokenSource(); var cancelToken = cancelTokenSource.Token; + accountTimeOutObserver.StartMonitoring(cancelToken); +var clipboard = provider.GetService()!; +var clipboardTimeoutObserver = new ClipboardTimeoutService(clipboard, environment, cancelToken); +#endregion try { runner.Run(args); } finally { + cancelTokenSource.Cancel(); ConsoleInteraction.ResetConsole(); } diff --git a/PWManager.CLI/Services/ClipboardTimeoutService.cs b/PWManager.CLI/Services/ClipboardTimeoutService.cs new file mode 100644 index 0000000..5fc7923 --- /dev/null +++ b/PWManager.CLI/Services/ClipboardTimeoutService.cs @@ -0,0 +1,56 @@ +using PWManager.Application.Context; +using PWManager.Application.Services.Interfaces; + +namespace PWManager.CLI.Services; + +public class ClipboardTimeoutService { + + private readonly IClipboard _clipboard; + private readonly IUserEnvironment _userEnv; + + private CancellationToken _programCancelToken; + + private CancellationTokenSource? _cancelTokenSource; + + public ClipboardTimeoutService(IClipboard clipboard, IUserEnvironment userEnv, CancellationToken cancellationToken) { + _clipboard = clipboard; + _userEnv = userEnv; + _programCancelToken = cancellationToken; + + _clipboard.OnClipboardUpdated += OnClipboardUpdated; + } + + private async Task ClipboardTimeoutTask(CancellationToken cancelToken) { + try { + cancelToken.ThrowIfCancellationRequested(); + await Task.Delay(GetClipboardTimeoutSpan(), cancelToken); + cancelToken.ThrowIfCancellationRequested(); + } + catch (OperationCanceledException) { + return; + } + + _clipboard.ClearClipboard(); + } + + + private TimeSpan GetClipboardTimeoutSpan() { + if (_userEnv.UserSettings is null) { + return TimeSpan.FromSeconds(30); + } + + return _userEnv.UserSettings.Timeout.ClipboardTimeOutDuration; + } + + private void OnClipboardUpdated(string val) { + if (string.IsNullOrWhiteSpace(val)) { + return; + } + + _cancelTokenSource?.Cancel(); + _cancelTokenSource?.Dispose(); + + _cancelTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_programCancelToken); + _ = ClipboardTimeoutTask(_cancelTokenSource.Token); + } +} \ No newline at end of file diff --git a/PWManager.Data/DependencyInjection.cs b/PWManager.Data/DependencyInjection.cs index 3bec14f..d82e2a2 100644 --- a/PWManager.Data/DependencyInjection.cs +++ b/PWManager.Data/DependencyInjection.cs @@ -27,7 +27,7 @@ public static IServiceCollection AddDataServices(this IServiceCollection service services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddSingleton(); return services; } } \ No newline at end of file diff --git a/PWManager.Data/System/Clipboard.cs b/PWManager.Data/System/Clipboard.cs index 2e0150f..3d0a442 100644 --- a/PWManager.Data/System/Clipboard.cs +++ b/PWManager.Data/System/Clipboard.cs @@ -5,6 +5,8 @@ namespace PWManager.Data.System; public class Clipboard : IClipboard { + public event Action OnClipboardUpdated; + public void WriteClipboard(string val) { if (OperatingSystem.IsWindows()) { var escaped = val.Replace("\n", "\\n").Replace("\"", "\"\""); @@ -23,6 +25,8 @@ public void WriteClipboard(string val) { else { throw new UserFeedbackException("Your Operating System does not support the clipboard functionality"); } + + OnClipboardUpdated(val); } public void ClearClipboard() { From 8ca804845c2022b1f386b66d16a84705c21f97e9 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 31 Mar 2024 17:45:02 +0200 Subject: [PATCH 6/7] Changed getsettings to userenv in groupcontroller --- PWManager.Application/Exceptions/MessageStrings.cs | 1 + PWManager.CLI/Controllers/GroupController.cs | 6 +++++- PWManager.CLI/Services/AccountTimeoutService.cs | 2 +- PWManager.CLI/Services/ClipboardTimeoutService.cs | 2 +- PWManager.CLI/UIstrings.cs | 7 +++++++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/PWManager.Application/Exceptions/MessageStrings.cs b/PWManager.Application/Exceptions/MessageStrings.cs index 747a5df..2ba565a 100644 --- a/PWManager.Application/Exceptions/MessageStrings.cs +++ b/PWManager.Application/Exceptions/MessageStrings.cs @@ -22,6 +22,7 @@ public static class MessageStrings { // GROUP Controller public const string NO_GROUPS_FOUND = "There are no groups in your database. Something is really wrong!"; + public const string NO_SETTINGS_IN_ENVIRONMENT = "There are not settings in your environment. Something is really wrong!"; // ---------------------------------------- // SETTINGS Controller diff --git a/PWManager.CLI/Controllers/GroupController.cs b/PWManager.CLI/Controllers/GroupController.cs index 8e3adf6..cd1c0be 100644 --- a/PWManager.CLI/Controllers/GroupController.cs +++ b/PWManager.CLI/Controllers/GroupController.cs @@ -85,7 +85,11 @@ private bool HandleDeletion() { return false; } - var settings = _settingsService.GetSettings(); + var settings = _userEnv.UserSettings; + if (settings is null) { + PromptHelper.PrintColoredText(ConsoleColor.Red, UIstrings.DELETE_ABORTED); + throw new UserFeedbackException(MessageStrings.NO_SETTINGS_IN_ENVIRONMENT); + } var isMainGroup = settings.MainGroup.MainGroupIdentifier.Equals(identifier); if (isMainGroup) { PromptHelper.PrintColoredText(ConsoleColor.Yellow, UIstrings.DELETE_STANDARD_GROUP); diff --git a/PWManager.CLI/Services/AccountTimeoutService.cs b/PWManager.CLI/Services/AccountTimeoutService.cs index e1f9040..e3e814c 100644 --- a/PWManager.CLI/Services/AccountTimeoutService.cs +++ b/PWManager.CLI/Services/AccountTimeoutService.cs @@ -44,7 +44,7 @@ private async Task TimeoutTask(CancellationToken cancelToken) { return; } ConsoleInteraction.ResetConsole(); - PromptHelper.PrintColoredText(ConsoleColor.Magenta, $"You were logged out due to inactivity for {GetAccountTimeoutSpan().Minutes} minutes"); + PromptHelper.PrintColoredText(ConsoleColor.Magenta, UIstrings.KickedDueToInactivityFor(GetAccountTimeoutSpan().Minutes)); System.Environment.Exit(0); } diff --git a/PWManager.CLI/Services/ClipboardTimeoutService.cs b/PWManager.CLI/Services/ClipboardTimeoutService.cs index 5fc7923..dd6f2ce 100644 --- a/PWManager.CLI/Services/ClipboardTimeoutService.cs +++ b/PWManager.CLI/Services/ClipboardTimeoutService.cs @@ -8,7 +8,7 @@ public class ClipboardTimeoutService { private readonly IClipboard _clipboard; private readonly IUserEnvironment _userEnv; - private CancellationToken _programCancelToken; + private readonly CancellationToken _programCancelToken; private CancellationTokenSource? _cancelTokenSource; diff --git a/PWManager.CLI/UIstrings.cs b/PWManager.CLI/UIstrings.cs index 96f517e..ec6533a 100644 --- a/PWManager.CLI/UIstrings.cs +++ b/PWManager.CLI/UIstrings.cs @@ -250,4 +250,11 @@ help To view this message """; // ---------------------------------------- + + // Timeout Service + + public static string KickedDueToInactivityFor(int minutes) => + $"You were logged out due to inactivity for {minutes} minutes"; + + // ----------------------------------------- } From 003b544d16a55b22973441074536c2cac206172b Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 31 Mar 2024 17:57:13 +0200 Subject: [PATCH 7/7] Account timeout string --- PWManager.CLI/Controllers/SettingsController.cs | 2 +- PWManager.CLI/UIstrings.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/PWManager.CLI/Controllers/SettingsController.cs b/PWManager.CLI/Controllers/SettingsController.cs index 39127b1..c762596 100644 --- a/PWManager.CLI/Controllers/SettingsController.cs +++ b/PWManager.CLI/Controllers/SettingsController.cs @@ -149,7 +149,7 @@ public bool ShowCurrentSettings() { Console.WriteLine(settings.Timeout.ClipboardTimeOutDuration.TotalSeconds + " s"); Console.ForegroundColor = defaultcolor; - Console.Write("Account Timeout: "); + Console.Write(UIstrings.ACCOUNT_TIMEOUT); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(settings.Timeout.AccountTimeOutDuration.TotalMinutes + " m"); Console.ForegroundColor = defaultcolor; diff --git a/PWManager.CLI/UIstrings.cs b/PWManager.CLI/UIstrings.cs index ec6533a..fae1ff4 100644 --- a/PWManager.CLI/UIstrings.cs +++ b/PWManager.CLI/UIstrings.cs @@ -142,6 +142,7 @@ internal static class UIstrings { public const string MAIN_GROUP = "Main Group: "; public const string CLIPPBOARD_TIMEOUT = "Clipboard Timeout: "; + public const string ACCOUNT_TIMEOUT = "Account Timeout: "; public const string PASSWORD_GEN_CRITERIA = "Password Generation Criteria:"; public const string MIN_LENGTH = "Min Length: "; public const string MAX_LENGTH = "Max Length: ";