Ejemplo n.º 1
0
        private async void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            bool success = false;

            if (PBKDF2.ValidatePassword(PswdCurrentPassword.Password, Admin ? AppState.AdminPassword : AppState.CurrentUser.Password) && PswdNewPassword.Password == PswdConfirmPassword.Password && PswdCurrentPassword.Password != PswdNewPassword.Password)
            {
                if (Admin && await AppState.ChangeAdminPassword(PBKDF2.HashPassword(PswdNewPassword.Password)).ConfigureAwait(false))
                {
                    AppState.DisplayNotification("Successfully changed administrator password.", "Time Clock");
                    success = true;
                }
                else if (!Admin)
                {
                    User newUser = new User(AppState.CurrentUser)
                    {
                        Password = PBKDF2.HashPassword(PswdNewPassword.Password)
                    };
                    if (await AppState.ChangeUserDetails(AppState.CurrentUser, newUser).ConfigureAwait(false))
                    {
                        AppState.DisplayNotification("Successfully changed user password.", "Time Clock");
                        AppState.CurrentUser.Password = newUser.Password;
                        success = true;
                    }
                }
            }
            else if (PswdCurrentPassword.Password == PswdNewPassword.Password)
            {
                AppState.DisplayNotification("The new password can't be the same as the current password.", "Time Clock");
                PswdNewPassword.Focus();
            }
            else if (PswdNewPassword.Password != PswdConfirmPassword.Password)
            {
                AppState.DisplayNotification("Please ensure the new passwords match.", "Time Clock");
                PswdConfirmPassword.Focus();
            }
            else
            {
                AppState.DisplayNotification("Invalid current password.", "Time Clock");
                PswdCurrentPassword.Focus();
            }

            if (success)
            {
                AppState.GoBack();
            }
        }
Ejemplo n.º 2
0
 private void PswdConfirmPassword_GotFocus(object sender, RoutedEventArgs e) => PswdConfirmPassword.SelectAll();