private void DoChangePassword() { if (!ValidateForm()) { lblMessage.Text = "Please provide the correct Old Password"; Exception exception = new Exception("New & confirmed passwords doesn't match."); } else { lblMessage.Text = ""; } if (newPasswordTextEdit.Text != confirmpasswordtextEdit.Text) { ViewHelper.ShowErrorMessage("New & confirmed passwords doesn't match."); activityLogger.SaveAction(repository.Users.FindByName(Thread.CurrentPrincipal.Identity.Name).UserID, 1, "Change Password Window", "New & confirmed passwords doesn't match."); } else if (SecurityHelper.ChangePassword(repository, Thread.CurrentPrincipal.Identity.Name, oldPasswordTextEdit.Text, newPasswordTextEdit.Text)) { ViewHelper.ShowSuccessMessage("Password changed successfully."); activityLogger.SaveAction(repository.Users.FindByName(Thread.CurrentPrincipal.Identity.Name).UserID, 1, "Change Password Window", "Password changed successfully."); this.Close(); } }
private void okCommand_Click(object sender, EventArgs e) { if (!passwordTextEdit.Text.Equals(confirmPasswordTextEdit.Text)) { ViewHelper.ShowErrorMessage("The password was not correctly confirmed. Please ensure that the password and confirmation match exactly."); return; } try { SecurityHelper.ChangePassword(user.UserId, passwordTextEdit.Text); ViewHelper.ShowSuccessMessage("The password has been set."); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception exception) { ViewHelper.ShowErrorMessage("Error occured while setting new password.", exception); } }
private void DoChangePassword() { if (!ValidateForm()) { return; } user = context.Users.First(u => u.UserName == userName); // Check if the current password and the supplied one are the same if (user.Password != SecurityHelper.HashPassword(oldPasswordTextEdit.Text)) { ViewHelper.ShowErrorMessage("The OLD password was not correctly confirmed. Please ensure that the password and confirmation match exactly."); return; } // Check if the newly supplied passwords match if (newPasswordTextEdit.Text != confirmTextEdit.Text) { ViewHelper.ShowErrorMessage("The NEW password was not correctly confirmed. Please ensure that the password and confirmation match exactly."); return; } // Save the changes to the database try { if (SecurityHelper.ChangePassword(user.UserId, newPasswordTextEdit.Text)) { ViewHelper.ShowSuccessMessage("Password changed successfully."); } this.DialogResult = DialogResult.OK; } catch (Exception exception) { ViewHelper.ShowErrorMessage("Error occured while changing password", exception); } }