2

I have custom form which has password field values and by using that user will be created in our website. So the requirement is to use password policy module functionalities to this form also. The form is able to show the policies below the password field and now those suggestions like use alphanumeric etc.. are not mandatory. But how I can mandate the password must contain alphanumeric etc etc... Please help me in this regard.

1
  • Do want policies to be included under your custom password field? or the validation error messages after submitting your form?
    – Ajay Reddy
    Commented Jun 12, 2018 at 7:23

1 Answer 1

0

You can use the 'password_confirm" #type in your form to get the exact field Drupal uses.

Add this to your Form function.

$form['account']['pass'] = array(
      '#type' => 'password_confirm',
      '#size' => 25,
      '#description' => t('To set or change the password, enter the new password in both fields.'),
    );

This will give you the field, javascript and the validator without any extra code.

1
  • password_confirm is only the standard default Drupal password field. It only checks that the user enters the same password twice. The question is regarding the Password Policy module which allows defining various rules for the password. I don't think there is any (easy) to integrate this onto a custom form. (D8/9)
    – liquidcms
    Commented Nov 22, 2022 at 3:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.