Hi,

Thanks for the great module.

So I wanted to use it on a D8 site with custom forms (including non-account, non-entity forms), and spotted this issue: 2562481

That has the D7 patch, and is tagged 8.x-3.x-dev but it felt wrong to piggy-back a purely D8 patch onto it, so I hope I'm doing the right thing by creating a new issue. If not please let me know.

I'll upload a patch which includes the idea of the 2562481 #23 patch to use hook_form_alter and test for the existence of a password form element.

I've tested the patch on 8.3.x and 8.4.x and it seems to work on both.

I've also included some other fixes for D8:

- rename parameter in password_policy_element_info_alter() to better match the core modules
- pass in the $form to _password_policy_show_policy() to catch a specific use case: when the form is 'user_register_form' and 'verify_mail' is set in the config
- extra parameters to password_policy_check_constraints_password_confirm_process() to be able to pass the $form to _password_policy_show_policy()
- extra check in _password_policy_constraints_validate() to test if there is a 'roles' element in the form before reading the values
- extra check in _password_policy_user_profile_form_submit() to test if it's an EntityForm before trying to save user data

Paddy

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

paddy.doyle created an issue. See original summary.

paddy.doyle’s picture

StatusFileSize
new10.62 KB
paddy.doyle’s picture

StatusFileSize
new10.63 KB

Fix coding standard fails.

paddy.doyle’s picture

StatusFileSize
new1.64 KB

Interdiff

dakku’s picture

D8 ++

paddy.doyle’s picture

StatusFileSize
new7.61 KB

Re-patched against latest dev version.

Simplified the patch with respect to changes to hook_form_alter(), so probably no point in an interdiff.

froboy’s picture

StatusFileSize
new7.63 KB

Re-patching against latest dev. Nothing changed other than some indexes.

froboy’s picture

I'm having trouble with this patch but need to pivot to something else. It looks like the array_combine around like 230 in function _password_policy_constraints_validate isn't producing the proper results.

I think that line should be replaced with:

    foreach ($roles as $role => $value) {
      if ($value) {
        $roles[$role] = $role;
      }
    }

I'm also seeing "The password does not satisfy the password policies." on every step of my custom, multi-step form, so it's possible this still needs to be adapted to account for multi-step forms.

froboy’s picture

StatusFileSize
new576 bytes
new7.69 KB

Patch with interdiff described above.

aohrvetpv’s picture

Status: Active » Needs work

Hello, thanks for the patches, all. I took a quick look and, unless I'm mistaken, the latest (#9) has several changes unrelated to this issue. For instance, type hinting is added to unrelated functions. Could the unrelated changes please be removed so we can review the code relevant to this issue?

froboy’s picture

@AohRveTPV thanks for taking a look. I did my best to recreate the patch from #6 as closely as possible with the latest dev, but I'm happy to remove things if you might clarify what seems extraneous?

The type hinting I see is in function _password_policy_constraints_table and function _password_policy_check_constraints and I agree that seems like it could be extraneous (although open to argument from @paddy.doyle if they're still listening). Are there other changes you'd like to see removed?

Thanks for clarifying.

froboy’s picture

Initial requested changes.

3ssom’s picture

Hello froboy,

I tried this against pretty much all d8 versions but it won't apply .. I also tried the previous patches but not luck either.

Regards
Essam

ant1’s picture

@3ssom: This patch seems to apply on '8.x-3.0-alpha5' for me.

But from there, I am stuck as well.
How do I trigger a password policy for a custom form (or in my case: Password Reset Landing Page)?

Thanks in advance.

3ssom’s picture

Hello

I just installed new Drupal install with Version: 8.x-3.0-alpha5 of this module to test it applies but still the same:

error: patch failed: password_policy.module:14
error: password_policy.module: patch does not apply

I'm not sure how did you apply it!

So me not getting this to work which I by the way need in my custom registrations form makes difficult to answer your question because I don't know how it should work! it might get attached to any ['account']['pass'] if it's == 'password_confirm'.

If you read the code that what you will see but unfortunately I can't see that .. if you could please make sure how did you apply the patch so we can help each other on this! I'm stuck also here.

Regards

ant1’s picture

My apologies, I made a mistake.
It should work on 8.x-3.x-dev using cweagans/composer-patches (well, it says it applied succesfully).

ant1’s picture

vsujeetkumar’s picture

Assigned: Unassigned » vsujeetkumar
vsujeetkumar’s picture

Assigned: vsujeetkumar » Unassigned
Status: Needs work » Needs review
StatusFileSize
new6.84 KB

Re-roll patch created, Please review.

vsujeetkumar’s picture

StatusFileSize
new6.85 KB

Please ignore previous patch(#19).

Status: Needs review » Needs work

The last submitted patch, 20: 2924009_20.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ant1’s picture

Issue tags: -Needs reroll

The patch does apply, but I see no changes.

sriharsha.uppuluri made their first commit to this issue’s fork.

kristen pol’s picture

Status: Needs work » Postponed (maintainer needs more info)

Thanks to everyone for your work on this issue.

As the 8.x is no longer supported, I'm postponing this issue for now and need feedback as to whether or not this issue is relevant to 4.0.x.

If it is, please reopen and change the version, make sure the issue summary is clear and complete, including concrete steps to reproduce, and reroll the patch. If it's not, please close.

If there is no response to this in a month addressing the above, it can be closed.

kristen pol’s picture

Note that I just closed #2562481: Apply password policies to account password elements on custom forms as fixed, which is the Drupal 7 version. Refer to that code if needed.