Exemplo n.º 1
0
        /// <summary>
        /// Returns the result of an attempt of autenticate.
        /// </summary>
        /// <param name="password">Entered password.</param>
        /// <returns></returns>
        public async Task <bool> Autenticate(string password, string encryptedPassword)
        {
            if (password == null || encryptedPassword == null)
            {
                throw new ArgumentNullException();
            }

            await Task.Delay(rng.Next(authDelay - authDelayRange, authDelay + authDelayRange));

            if (cryptographer != null)
            {
                cryptographer.ChangeKey(password);
                return(cryptographer.Decrypt(encryptedPassword) == password);
            }
            else
            {
                return(encryptedPassword == password);
            }
        }
Exemplo n.º 2
0
        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;
        }