private void validateEmpty(string name, object sender) { try { if (name == "PasswordBox") { if ((sender as PasswordBox).Name == "pb_oldPassword") { if (((PasswordBox)sender).Password.Equals("")) { HelpClass.showPasswordValidate((PasswordBox)sender, p_errorOldPassword, tt_errorOldPassword, "trEmptyPasswordToolTip"); } else { HelpClass.clearPasswordValidate(pb_oldPassword, p_errorOldPassword); } } else if ((sender as PasswordBox).Name == "pb_newPassword") { if (((PasswordBox)sender).Password.Equals("")) { HelpClass.showPasswordValidate((PasswordBox)sender, p_errorNewPassword, tt_errorNewPassword, "trEmptyPasswordToolTip"); } else { HelpClass.clearPasswordValidate(pb_newPassword, p_errorNewPassword); } } else if ((sender as PasswordBox).Name == "pb_confirmPassword") { if (((PasswordBox)sender).Password.Equals("")) { HelpClass.showPasswordValidate((PasswordBox)sender, p_errorConfirmPassword, tt_errorConfirmPassword, "trEmptyPasswordToolTip"); } else { HelpClass.clearPasswordValidate(pb_confirmPassword, p_errorConfirmPassword); } } } } catch (Exception ex) { HelpClass.ExceptionMessage(ex, this); } }
private async void Btn_save_Click(object sender, RoutedEventArgs e) {//save try { HelpClass.StartAwait(grid_main); #region validate bool wrongOldPasswordLength = false, wrongNewPasswordLength = false, wrongConfirmPasswordLength = false; //chk empty old password if (pb_oldPassword.Password.Equals("")) { HelpClass.validateEmpty(pb_oldPassword.Password, p_errorOldPassword); } else { //chk password length wrongOldPasswordLength = chkPasswordLength(pb_oldPassword.Password); if (wrongOldPasswordLength) { HelpClass.showPasswordValidate(pb_oldPassword, p_errorOldPassword, tt_errorOldPassword, "trErrorPasswordLengthToolTip"); } else { HelpClass.clearPasswordValidate(pb_oldPassword, p_errorOldPassword); } } //chk empty new password if (pb_newPassword.Password.Equals("")) { HelpClass.showPasswordValidate(pb_newPassword, p_errorNewPassword, tt_errorNewPassword, "trEmptyPasswordToolTip"); } else { //chk password length wrongNewPasswordLength = chkPasswordLength(pb_newPassword.Password); if (wrongNewPasswordLength) { HelpClass.showPasswordValidate(pb_newPassword, p_errorNewPassword, tt_errorNewPassword, "trErrorPasswordLengthToolTip"); } else { HelpClass.clearPasswordValidate(pb_newPassword, p_errorNewPassword); } } //chk empty confirm password if (pb_confirmPassword.Password.Equals("")) { HelpClass.showPasswordValidate(pb_confirmPassword, p_errorConfirmPassword, tt_errorConfirmPassword, "trEmptyPasswordToolTip"); } else { //chk password length wrongConfirmPasswordLength = chkPasswordLength(pb_confirmPassword.Password); if (wrongConfirmPasswordLength) { HelpClass.showPasswordValidate(pb_confirmPassword, p_errorConfirmPassword, tt_errorConfirmPassword, "trErrorPasswordLengthToolTip"); } else { HelpClass.clearPasswordValidate(pb_confirmPassword, p_errorConfirmPassword); } } #endregion #region save if ((!pb_oldPassword.Password.Equals("")) && (!wrongOldPasswordLength) && (!pb_newPassword.Password.Equals("")) && (!wrongNewPasswordLength) && (!pb_confirmPassword.Password.Equals("")) && (!wrongConfirmPasswordLength)) { //get password for logined user string loginPassword = MainWindow.userLogin.password; string enteredPassword = Md5Encription.MD5Hash("Inc-m" + pb_oldPassword.Password); if (!loginPassword.Equals(enteredPassword)) { HelpClass.showPasswordValidate(pb_oldPassword, p_errorOldPassword, tt_errorOldPassword, "trWrongPassword"); } else { HelpClass.clearPasswordValidate(pb_oldPassword, p_errorOldPassword); bool isNewEqualConfirmed = true; if (pb_newPassword.Password.Equals(pb_confirmPassword.Password)) { isNewEqualConfirmed = true; } else { isNewEqualConfirmed = false; } if (!isNewEqualConfirmed) { HelpClass.showPasswordValidate(pb_newPassword, p_errorNewPassword, tt_errorNewPassword, "trErrorNewPasswordNotEqualConfirmed"); HelpClass.showPasswordValidate(pb_confirmPassword, p_errorConfirmPassword, tt_errorConfirmPassword, "trErrorNewPasswordNotEqualConfirmed"); } else { HelpClass.clearPasswordValidate(pb_newPassword, p_errorNewPassword); HelpClass.clearPasswordValidate(pb_confirmPassword, p_errorConfirmPassword); //change password string newPassword = Md5Encription.MD5Hash("Inc-m" + pb_newPassword.Password); MainWindow.userLogin.password = newPassword; int s = await userModel.Save(MainWindow.userLogin); if (s > 0) { if (!Properties.Settings.Default.password.Equals("")) { Properties.Settings.Default.password = pb_newPassword.Password; Properties.Settings.Default.Save(); } Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopPasswordChanged"), animation: ToasterAnimation.FadeIn); this.Close(); } else { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); } } } } #endregion HelpClass.EndAwait(grid_main); } catch (Exception ex) { HelpClass.EndAwait(grid_main); HelpClass.ExceptionMessage(ex, this); } }