public int ChangePassword(string oldPassword, string newPassword, int userId) { if (IsPasswordMatched(oldPassword, userId)) { return(_userGateway.ChangePassword(newPassword, userId)); } throw new Exception("Old password did not match!"); return(0); }
private void SaveButton_Click(object sender, EventArgs e) { try { if (userName.Text == "" || password.Text == "" || newUserName.Text == "" || newPassword.Text == "" || confirmPassword.Text == "" || newPassword.Text != confirmPassword.Text) { cMessageBox.Warning("Please Fillout all fields and Make Sure That New and Confirm Password both are same"); } else { if (!Un.IsMatch(newUserName.Text.Trim())) { cMessageBox.Information("Your UserName is not in Correct Format"); } if (!pw.IsMatch(newPassword.Text.Trim())) { cMessageBox.Information("Your Password is not in Correct Format"); } else { UserGateway userGateway = new UserGateway(); User user = new User(); user.UserName = userName.Text.Trim(); user.Password = password.Text.Trim(); bool isVaild = userGateway.isVaildUser(user); if (isVaild) { user.NewUserName = newUserName.Text.Trim(); user.NewPassword = newPassword.Text.Trim(); userGateway.ChangePassword(user); cMessageBox.Success("Seccessfully Updated Password and UserName"); Application.Exit(); } else { cMessageBox.Failed("Your Current UserName or Password is not Correct"); } } } } catch (Exception) { cMessageBox.Failed("Try Again"); } }