private void CheckCredentials(object parameter) { if (parameter == null) { return; } var passwordBox = (PasswordBox)parameter; _password = passwordBox.Password; var isUserCredentialsCorrect = GetRepository().CheckUserCredentials(_username, EncryptPassword.Encrypt(_password)); if (isUserCredentialsCorrect != null && isUserCredentialsCorrect.GetEnumerator().MoveNext()) { var returnedUser = isUserCredentialsCorrect.FirstOrDefault <User>(); MainViewModel.LoggedUser = returnedUser; var mainView = new Views.MainView(); var mainVM = new MainViewModel(); mainView.DataContext = mainVM; mainView.Show(); CloseAction(); } else { MessageBox.Show("Incorrect Credentials"); } }
private async void AccessCheckAsync(object parameter) { Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; var passwordBox = parameter as PasswordBox; Password = passwordBox.Password; autenticator.ChangeKey(Password); bool isAutenticate = await autenticator.Autenticate(Password, setting.GetByKey(SecureManager.PasswordKey)); Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow; if (isAutenticate) { SecureManager.Key = Password; Views.MainView mainView = new Views.MainView(); foreach (Window item in Application.Current.Windows) { if (item.DataContext == this) { item.Close(); } } mainView.Show(); } else { MessageBox.Show("Wrong password."); } }
private async void TryWritePassword() { IsUiAvailable = false; if (Password == ConfirmPassword) { if (Password.Length >= minLength && Password.Length <= maxLenght) { if (Regex.IsMatch(Password, @"^\d+$")) // Is digits only { SecureManager.Key = Password; string value = Password; if (cryptographer != null) { cryptographer.ChangeKey(SecureManager.Key); value = cryptographer.Encypt(value); } setting.Write(SecureManager.PasswordKey, value); LoadingPanelVisibility = Visibility.Visible; OnPropertyChanged(nameof(LoadingPanelVisibility)); Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait; if (await Initialize()) { Views.MainView mainView = new Views.MainView(); foreach (Window item in Application.Current.Windows) { if (item.DataContext == this) { item.Close(); } } Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow; mainView.ShowDialog(); } else { Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow; LoadingPanelVisibility = Visibility.Hidden; OnPropertyChanged(nameof(LoadingPanelVisibility)); setting.Delete(SecureManager.PasswordKey); } } else { MessageBox.Show("Password should consist only of digits."); } } else { MessageBox.Show($"The number of password characters must be between {minLength} and {maxLenght}."); } } else { MessageBox.Show("Entered passwords are different."); } IsUiAvailable = true; }
//public int TotalTasks { get { return totalTasks; } } #endregion #region Constructor public MainViewModel(Models.AlgorithmsModel malgorithms, Models.SesionModel msesion, Views.MainView vmain) { // Models references this._malgorithms = malgorithms; this._msesion = msesion; this._vmain = vmain; // Initialize TreeViewItems with drives this._drives = new ObservableCollection<DirectoryViewModel>(); foreach (string drive in Directory.GetLogicalDrives()) { this._drives.Add(new DirectoryViewModel(new DirectoryInfo(@drive))); } // Initialize Original-Algorithms-Task-Results ListView Collections this._oimages = new ObservableCollection<OriginalCollectionViewModel>(); this._algorithms = new ObservableCollection<AlgorithmViewModel>(); foreach (Models.AlgorithmModel algorithm in this._malgorithms.Algorithms) { // only a reference to the object if (algorithm != null) this._algorithms.Add(new AlgorithmViewModel(algorithm)); } _tasks = new ObservableCollection<TaskViewModel>(); _atask = new ObservableCollection<ActiveTaskViewModel>(); this.aposition = 0; this.tposition = -1; this.atposition = -2; this.tenabled = false; this.cameraIndex = 0; this._cpVisible = "Hidden"; this._taenabled = false; //this._vmain.circularProgressBar.StopSpinning(); }