password_verify($old_password)) { $this->context['error_form'] = new ValidationError(['You entered your old password incorrectly.']); return; } if ($new_password != $repeat_password) { $this->context['error_form'] = new ValidationError(['Passwords don\'t match']); return; } try { $curr_user = CURRENT_USER; if (UserModel::valid_password($new_password) !== true) { $errors = UserModel::valid_password($new_password); throw new ValidationError($errors); } // After validations, save new password $curr_user->field_password = UserModel::password_hash($new_password); $curr_user->save(); redirect_to(get_permalink('users:profile')); } catch (ValidationError $ex) { $this->context['error_form'] = $ex; return; } catch (\Exception $ex) { $this->context['error_message'] = 'Unexpected error'; return; } } }