예제 #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();
            }
        }
 public ChangePasswordPage(bool admin = false)
 {
     InitializeComponent();
     _blnAdmin = admin;
     PswdCurrentPassword.Focus();
 }
예제 #3
0
 public ChangePasswordPage()
 {
     InitializeComponent();
     PswdCurrentPassword.Focus();
 }