Пример #1
0
        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.");
            }
        }