Make a password security check for the register form I have a register form that is output in a controller using the following code.

 $form = $this-&gt;getUserProfileForm();

    return [
      '#theme' =&gt; 'maubl_user_inscription',
      '#form' =&gt; $form,
    ];
  }

  protected function getUserProfileForm() {
    $entity = \Drupal::service('entity.manager')
      -&gt;getStorage('user')
      -&gt;create(array());

    $formObject = \Drupal::service('entity.manager')
      -&gt;getFormObject('user', 'default')
      -&gt;setEntity($entity);

    $form = \Drupal::formBuilder()-&gt;getForm($formObject);

    return $form;
  }


In a custom module, I'm using the following code to alter the password.

function maubl_user_form_user_form_alter(&amp;$form, \Drupal\Core\Form\FormStateInterface $formState) {
  $form['actions']['submit']['#submit'][] = 'maubl_user_form_login_after_registration';
  $form['account']['pass']['#process'][] = 'maubl_user_form_user_register_form_process_pass';
}

function maubl_user_form_user_register_form_process_pass(&amp;$element, \Drupal\Core\Form\FormStateInterface $form_state, &amp;$complete_form) {
  $element = \Drupal\Core\Render\Element\PasswordConfirm::processPasswordConfirm($element, $form_state, $complete_form);
  $element['pass1']['#placeholder'] = t('Password');
  $element['pass2']['#placeholder']= t('Confirm pwd');
}


Yet, any password would be accepted as long as they are the same. I want something like password_confirm to check if there are special characters, special length etc, but I couldn't figure out how to make it works.

When I try to use the following code, nothing happens.

function mymodule_form_user_register_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
  $form['account']['pass']['#process'][] = 'mymodule_form_user_register_form_process_pass';
}
It seems like you might want to look into the Password Policy module which probably has a lot of the features you are trying to rebuild.

I also wonder whether it makes sense to build your own user inscription form instead of altering the existing core registration form. Altering forms tends to result in easier integrations with existing modules.