private async void SetUpMasterKey() { string newPwd = passwordBoxNewPassword.Password; progressBarLoading.IsIndeterminate = true; bool success = true; string error = ""; await Task.Run(() => { var result = _ioSecurity.SetUpMasterKey(newPwd); if (!result.Success) { success = false; error = result.ErrorMessage; } }); progressBarLoading.IsIndeterminate = false; if (success) { await this.ShowMessageAsync(LanguageChanger.Instance["StartupView_CodeBehind_Success"], LanguageChanger.Instance["StartupView_CodeBehind_Code3"]); gridSetupMasterKey.Visibility = Visibility.Collapsed; gridLogin.Visibility = Visibility.Visible; } else { await this.ShowMessageAsync(LanguageChanger.Instance["StartupView_CodeBehind_Error"], error); } }
private void SetUpMasterKey(Action action) { PasswordMasker masker = new PasswordMasker(); string key = ""; do { key = masker.Mask("Set password (length>5): "); if (String.IsNullOrEmpty(key) || key.Length <= 5) { Write("Password length must be greater than 5 chars!"); ReadLine(); Clear(); } else if (File.Exists(Global.MasterKeyLocation) && _iOSecurity.Login(key).Success) { Write("You cannot input the same password!"); ReadLine(); Clear(); } else { break; } } while (true); WriteLine("Loading..."); MainResult result = _iOSecurity.SetUpMasterKey(key); if (result.Success) { WriteLine("Password has been set"); } else { WriteLine($"Error: `{result.ErrorMessage}`"); } action(); }