Hello,

I know that "Password policies only apply to passwords set via user forms in the web interface".

But... I’ve installed Password policies. When a user (who forgets his password) wants to reset his password (following the link on the login page), he receives a link by email (password recovery link) . When he follows this link, he fills a form but the Password policies is not applied. It’s like it is not activated.

Is it normal behavior ? I thought that it was a form from web interface.

It works when I rest the password in the admin. I can see the plugin activated.

CommentFileSizeAuthor
#63 password_policy-prlp-63.patch8.65 KBwadator
#60 password_policy_reset_validation.patch400 bytesrohan-sinha
#56 password_policy-prlp-56.patch8.54 KBwadator
#56 password_policy-prlp-56.patch8.54 KBwadator
#51 3078741-51-password-policy-reset-form.patch8.45 KBalexrayu
#48 password_policy-prlp-45.patch11.12 KBciprian.jitaru
#45 password_policy-prlp-44.patch10.18 KBciprian.jitaru
#44 password_policy-prlp-43.patch10.74 KBciprian.jitaru
#43 password_policy-prlp-43.patch11.12 KBciprian.jitaru
#42 password_policy-prlp-42.patch7.74 KBsfuchsbe
#38 interdiff-35-38.txt5.47 KBilya.no
#38 password_policy-prlp-38.patch6.63 KBilya.no
#35 password_policy-prlp-35.patch5.09 KBsorlov
#34 password_policy-prlp-34.patch4.98 KBvacho
#33 password_policy-prlp-14.patch4.68 KBSbonder
#31 password_policy-Reset-31.patch2.31 KBjpatel657
#30 password_policy-Reset-30.patch2.22 KBjpatel657
#27 password_policy-prlp-27.patch5.04 KBvacho
#25 password_policy-prlp-25.patch5.86 KBvacho
#24 password_policy-prlp-24.patch5.87 KBvacho
#21 password_policy-prlp-15.patch5.7 KBv.dovhaliuk
#20 password_policy-prlp-15.patch5.69 KBv.dovhaliuk
#18 3078741-password_policy-prlp.patch4.5 KBbwoods
#17 password_policy-prlp-14.patch4.67 KBamarlata
#13 password_policy-prlp-2943105-13.patch3.54 KBjcnventura
#13 interdiff_12_13.txt1.74 KBjcnventura
#12 3078741-12.patch2.6 KBjcnventura
#12 interdiff_11_12.txt2.06 KBjcnventura
#11 3078741-11.patch1.74 KBjcnventura
#11 interdiff_7_11.txt1.67 KBjcnventura
#7 3078741-7.patch2.87 KBvacho
#6 3078741-6.patch3.32 KBvacho
#5 3078741-5.patch2.93 KBvacho
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

vinyl_roads created an issue. See original summary.

aohrvetpv’s picture

I believe password policies should apply in that case. I'll plan to investigate. Thanks for reporting the bug.

sébastien-fr’s picture

I’ve installed a Drupal clean install (8.7.6) and the module Password Policy works as expected, both for admin and authenticated user

So on the website I’m working on where the module is not working : I’m sure (I've tested on this clean install) it is because I’ve installed Simple Password Reset which skips the unnecessary and confusing one-time login form and I think Password policy is not applied.

Could you help me to investigate and find a solution ? I will check this ans ask Simple Password Reset developer too.

vacho’s picture

StatusFileSize
new2.93 KB

This first patch is only an approach to get the end solution.

The idea is to add the form elements to validate to form user_pass_reset, such as the module did for user_form and user_register_form

To get this patch finished, we need to implement correctly the ajax validation for the field "pass" at this time it is not working.

vacho’s picture

StatusFileSize
new3.32 KB

This patch fix problem with $form['pass'] where this element not found at hook_form_FORM_ID_alter (password_policy_form_user_pass_reset_alter) but still not work correctly with ajax. At this time the function ajax is not calling.

vacho’s picture

StatusFileSize
new2.87 KB

This patch is identical to 7 but for the dev branch. (with ajax issue still)

vacho’s picture

Title: Is Password policies apply to "Forgot password" form ? » Password policies not apply to "Forgot password" form
Version: 8.x-3.0-alpha5 » 8.x-3.x-dev
andypost’s picture

Status: Active » Needs review
Issue tags: +Needs tests
andypost’s picture

jcnventura’s picture

StatusFileSize
new1.67 KB
new1.74 KB

Moving the module weight change to #2943105: Password policy and Password Reset Landing Page.

Also, I think I can make this patch smaller.

However, my main issue with the patch, is that I see the password_policy well enough already in the password reset form, so I have no idea why this would be needed.

jcnventura’s picture

StatusFileSize
new2.06 KB
new2.6 KB

Well, that didn't work. Main reason was that the _password_policy_constraints_table() function doesn't exist. After that came the fact that the user really is anonymous at this point (talking about the password reset form....).

jcnventura’s picture

StatusFileSize
new1.74 KB
new3.54 KB

And it still doesn't work if I patch prlp to validate the passwords. One final try at fixing this before I remove prlp from this site...

jcnventura’s picture

Status: Needs review » Needs work

I was wondering what that 'dsu_security_validate' from @vacho's #7 patch was. It seems it's something from his particular project. There's more errors even removing that one line, and I'm giving up on getting password_policy and prlp to work together.

espurnes’s picture

Hi jcnventura,

dsu_security_validate is, indeed, part of another installation profile and that code shouldn't be there.

I've found that the problem seems related, but maybe not limited, to prlp and this issue #3143391: Password reset form validation allows non-matching passwords. It bypasses repeat password validation.

Have you managed to make password_policy + prlp work?

Update:
I see that the issue happens with password_policy 8.x-3.0-beta1. Downgrading to 8.x-3.0-alpha5 seems that solves the problem and form validates again.

jcnventura’s picture

We uninstalled prlp.

amarlata’s picture

StatusFileSize
new4.67 KB

Fixed error after applying the patch #13.

Error: Call to undefined method Drupal\user\Form\UserPasswordResetForm::getEntity() in _password_policy_user_profile_form_submit() (line 319 of modules/contrib/password_policy_prev/password_policy.module).
_password_policy_user_profile_form_submit(Array, Object)
call_user_func_array('_password_policy_user_profile_form_submit', Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 591)
Drupal\Core\Form\FormBuilder->processForm('user_pass_reset', Array, Object) (Line: 320)
Drupal\Core\Form\FormBuilder->buildForm('Drupal\user\Form\UserPasswordResetForm', Object) (Line: 60)
Drupal\prlp\Controller\PrlpController->prlpResetPassLogin(Object, '2021', '1595421632', '3ua2AHeXDDZADL0qBP0MaWM9G2rAOTAQcCk6h4hBFoI')
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

bwoods’s picture

StatusFileSize
new4.5 KB

I used the patch from @amarlata and removed the line referring to dsu_security_validate. This seems to solve the issue. Here is my overall setup in composer:

"drupal/password_policy": "3.x-dev"
"drupal/prlp": "1.x-dev"

"drupal/prlp": {
"Password reset form validation allows non-matching passwords": "https://www.drupal.org/files/issues/2020-08-25/prlp-form_validation-3143..."
},
"drupal/password_policy": {
"Password policies not apply to 'Forgot password' form": "https://www.drupal.org/files/issues/2020-09-22/3078741-password_policy-p...",
"Password policy and Password Reset Landing Page": "https://www.drupal.org/files/issues/2020-07-20/password_policy-prlp-2943..."
}

sorina.hriban’s picture

Found an issue. If using forgot password form, the password reset field remains 1 because of the condition:
$uid && ($current_pass || $form_state->get('user_pass_reset')) && $new_pass
When resetting password there is not current pass field, nor user_pass_reset.

v.dovhaliuk’s picture

StatusFileSize
new5.69 KB

Fixed problem, when Ajax callback does not apply to the password field after applying patch #18.

There is still a problem with the Ajax form on the "password reset landing page". Problem in \ Drupal \ user \ Controller \ UserController :: getResetPassForm
$ session-> remove ('pass_reset_timeout');
$ session-> remove ('pass_reset_hash');

When Ajax is running, got error 403 Forbidden.

v.dovhaliuk’s picture

StatusFileSize
new5.7 KB
v.dovhaliuk’s picture

v.dovhaliuk’s picture

Patch updated.

vacho’s picture

StatusFileSize
new5.87 KB

This patch can apply.

vacho’s picture

StatusFileSize
new5.86 KB

Fixed trailing whitespace issue

andypost’s picture

  1. +++ b/password_policy.module
    @@ -13,6 +13,103 @@ use Drupal\user\UserInterface;
    +  // Check for specific conditions.
    +  // $show_password_policy_status = _password_policy_show_policy();
    +  $show_password_policy_status = TRUE;
    

    why the line commented out?

  2. +++ b/password_policy.module
    @@ -13,6 +13,103 @@ use Drupal\user\UserInterface;
    +  $uid = \Drupal::routeMatch()->getRawParameter('uid');
    +  $user = \Drupal::entityTypeManager()->getStorage('user')->load($uid);
    +  if ($user === NULL || !$user->isActive()) {
    +    // Blocked or invalid user ID, so deny access. The parameters will be in
    +    // the watchdog's URL for the administrator to check.
    +    throw new AccessDeniedHttpException();
    

    why you're picking raw parameter? it should be converted already, otherwise it needs comment why you need to load entity

  3. +++ b/password_policy.module
    @@ -13,6 +13,103 @@ use Drupal\user\UserInterface;
    +  // Load form if relevant.
    +  if ($show_password_policy_status) {
    +    $form['password_policy_status'] = [
    

    it could use #access => $show_password_policy instead of condition

  4. +++ b/password_policy.module
    @@ -13,6 +13,103 @@ use Drupal\user\UserInterface;
    +  if (!is_null($expiration) && $expiration['value'] === FALSE) {
    +    $form_state->setValue('field_password_expiration', ['value' => 0]);
    

    if empty() should be enough

  5. +++ b/password_policy.module
    @@ -13,6 +13,103 @@ use Drupal\user\UserInterface;
    +  $uid = \Drupal::routeMatch()->getRawParameter('uid');
    +  $user = \Drupal::entityTypeManager()->getStorage('user')->load($uid);
    

    I bet password reset is not shown for authorized user

  6. +++ b/password_policy.module
    @@ -13,6 +13,103 @@ use Drupal\user\UserInterface;
    +  $uid = \Drupal::routeMatch()->getRawParameter('uid');
    +  $user = \Drupal::entityTypeManager()->getStorage('user')->load($uid);
    

    Not clear why you're loading the entity again

  7. +++ b/password_policy.module
    @@ -148,10 +245,12 @@ function password_policy_check_constraints_password_confirm_process(array $eleme
    -  $password_invisible = empty($form['account']['pass']) || (isset($form['account']['pass']['#access']) ? !$form['account']['pass']['#access'] : FALSE);
    +  if (isset($form['account'])) {
    +    $password_invisible = empty($form['account']['pass']) || (isset($form['account']['pass']['#access']) ? !$form['account']['pass']['#access'] : FALSE);
     
    -  if ($password_invisible) {
    -    $form['account']['password_policy_status']['#access'] = FALSE;
    +    if ($password_invisible) {
    +      $form['account']['password_policy_status']['#access'] = FALSE;
    +    }
    

    useless change

  8. +++ b/password_policy.module
    @@ -256,6 +355,10 @@ function password_policy_user_presave(EntityInterface $entity) {
    +  if (!isset($form['account'])) {
    +    // For reset pass form.
    +    return $form['password_policy_status'];
    

    weird code reuse

vacho’s picture

StatusFileSize
new5.04 KB

Thanks, @andypost for the corrections.

1. Fixed
2. Fixed
3. We can use if because there are 4 form elements that we write in this case.
4. Fixed
5. Password reset is for one user because no user can't reset one password.
6. Reload entity again due to is into ajax method.
7. Fixed
8. Fixed

vacho’s picture

Status: Needs work » Needs review
jpatel657’s picture

Assigned: Unassigned » jpatel657
jpatel657’s picture

Assigned: jpatel657 » Unassigned
StatusFileSize
new2.22 KB

This has been fixed. Please review.

jpatel657’s picture

StatusFileSize
new2.31 KB

above comment is not working on registration page
Url: https://www.drupal.org/project/password_policy/issues/3078741#comment-14...

Use this page

vacho’s picture

qjpatel657 needs to explain why you alter the patch #27 also your last patch only commented on some code lines, if this line is not required should be removed.

Sbonder’s picture

StatusFileSize
new4.68 KB
vacho’s picture

StatusFileSize
new4.98 KB

Patch updated an applicable to last version of the module.

sorlov’s picture

StatusFileSize
new5.09 KB

rerolled patch #34 to latest 8.x-3.x version

narres’s picture

Patch #35 isn't working for me using 8.x.-3.1 with "Could not apply patch!".
With 3.x-de@dev (dev-3.x 103a2c2) I'm getting the "Error: Class 'AccessDeniedHttpException' not found in ... password_policy.module on line 74".

sorlov’s picture

Status: Needs review » Needs work
ilya.no’s picture

Status: Needs work » Needs review
StatusFileSize
new6.63 KB
new5.47 KB

I've fixed above error by removing throwing access denied exception, since it's not quite right place for this.
With my update server side validation for the form works, but ajax doesn't work on form and table with constrains stays the same. Need to dig, whether it's my local problem or invalid code, so, please, review, if there is anything wrong with it.

vacho’s picture

Code and solution work on my side.

vacho’s picture

Status: Needs review » Reviewed & tested by the community
sfuchsbe’s picture

Status: Reviewed & tested by the community » Needs work

Unfortunately, I have to reopen the task. The first test case I checked was failing.

Preconditions:

  • Have multiple roles in the system
  • Have separate PW policies for each role

Expected behavior:

  • All policies affecting the roles of the user should be displayed and used

Current behavior:

  • Only the policies for role "authenticated" are used

Because I urgently require this fix I will try to contribute an update until end of this week. In case anyone wants to pick it up - feel free. I won't complain ;)
As this was only the first test, I'm going to test additional use cases as well and in case of any findings will include fixes into my contribution.

sfuchsbe’s picture

StatusFileSize
new7.74 KB

So, I did some additional testing and found other issues:

  • The AJAX call on the PRLP is not working. Actually the core PW reset mechanism is relying on two session values that are deleted after the first usage. In the AJAX call those values are missing and therefore Core is refusing this call and throws an exception. PRLP module is simply injecting those values back before submit. So I assume we have to do the same in this module.
  • The response of the AJAX call is empty. Reason is the different nesting of the form array. In user edit form there is an additional [account] element which is missing on PRLP. But the after_build callback is still relying on that array nesting and breaking the AJAX callback content. We need to take care of this as well in after_build.
  • When finally submitting the PRLP the password will be changed and properly validated. But the timestamp for last PW reset is not updated. There is a submit handler added that should do this job. But in this function the script is looking for either the current PW (which is not requested on PRLP) or a value from form_state which is actually never set. The condition will always result in "false"

I tried to fix all the issues I mentioned above - including the first one related to the roles not being properly respected.

Nevertheless, I think there is additional room for improvements before accepting this fix.

  • There is a change in a signature of one function introducing a new parameter. The parameter was added at the beginning which requires update of all usages of this function. This is already covered but we don't know which other patch might use this as well and now stop working.
  • The Core implementation of these two session values is intentionally for security reasons. Adding those values back to the session might create a security issue that we are currently not aware of.
  • Having these two different structures of the form array is creating a lot of duplicated code. This can be further optimized.

I would highly appreciate if anybody could test my patch as well and provide feedback. This is now open for so many months. Let's bring this to an end!

ciprian.jitaru’s picture

StatusFileSize
new11.12 KB

Added some fixes.

ciprian.jitaru’s picture

StatusFileSize
new10.74 KB
ciprian.jitaru’s picture

StatusFileSize
new10.18 KB

Fixed some issues.

ciprian.jitaru’s picture

ciprian.jitaru’s picture

ciprian.jitaru’s picture

StatusFileSize
new11.12 KB
ciprian.jitaru’s picture

john franklin’s picture

Thanks for the patch, @sfuchsbe! Your patch in #42 is the first one that actually works for us.

One thing we noticed in our testing. The function _password_policy_user_pass_reset_form_validate() doesn't seem to be needed, and causes duplicate entries in the password_policy_history table.

alexrayu’s picture

Thank you @sfuchsbe,

I have tested and cleaned up your patch, re-rolling here.

Some notes:
1. _password_policy_user_pass_reset_form_validate() is required, and should not be removed (see #50).
2. The duplicated history records in my case come form the double user update hook call, one from password_policy hook and from the "prlp" module. (yes, there is such module, and it's a different module https://www.drupal.org/project/prlp). But it's nothing that we probably can/should fix here - these are two separate modules.

Please review the updated patch.

alexrayu’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 51: 3078741-51-password-policy-reset-form.patch, failed testing. View results

the_g_bomb’s picture

Password duplicates could be related to another issue that may have been fixed in this issue:
https://www.drupal.org/project/password_policy/issues/3269065
the duplicates can be removed using the update in the follow-up issue:
https://www.drupal.org/project/password_policy/issues/3266140
FYI, there is also an open issue for getting PRLP support added:
https://www.drupal.org/project/password_policy/issues/2362023

Would it be worth reattempting the fix with those patches applied?

john franklin’s picture

The patch in #3269065: Data too long for column 'field_last_password_reset_value': incorrect datetime format does not fix the duplicate password history issue, at least not when PRLP is installed.

The patch in #2362023: Support for Password Reset Landing Page (PRLP) conflicted with this one, because both define password_policy_form_user_pass_reset_alter(). As we already have an older version of the patch here working, we decided to continue using the patches here.

We added a separate (internal) patch to Password History that checks if we've already written an item in the password history table for the current UID and the current request timestamp, and skip if one already exists. If/when a new version of this module is released, we'll adopt whichever solution is chosen.

A fix to handle duplicate history entries is supposed to be in #2867320: Password Policy History module wrong behaviour, and that's the best place for it. Debouncing the history update is the responsibility of the Password History module.

wadator’s picture

StatusFileSize
new8.54 KB
new8.54 KB

rerolled patch #51 to 8.x-3.1 version

wadator’s picture

sophiavs’s picture

Assigned: Unassigned » sophiavs

Hi, i'll try to work on this

sophiavs’s picture

Assigned: sophiavs » Unassigned

I couldn't reproduce the error in the dev version.
The email to reset the password came with [user:one-time-login-url] link, in that way i can only log in and in the edit page the validations work as it was supposed to work. If there is another link that i should put in the email to try to reproduce this error please comment here.

rohan-sinha’s picture

StatusFileSize
new400 bytes

this Patch will enable the password policy validation on reset password page.
Add this patch in Composer.json under Drupal/password_policy .

andypost’s picture

joe_carvajal’s picture

Just to push this up, the patch at #56 looks nice but it does not apply with new 4.0.0 version.
I confirm that the issues persist at 4.0.0.

wadator’s picture

Version: 8.x-3.x-dev » 4.0.0
Status: Needs work » Needs review
StatusFileSize
new8.65 KB

Added a new patch for 4.0 version.

kristen pol’s picture

Title: Password policies not apply to "Forgot password" form » Password policies not apply to "Forgot password" form.
Version: 4.0.0 » 4.0.x-dev
Status: Needs review » Needs work

Still needs tests. No more rerolls or updates until there are tests please, but obviously reroll if you add tests and it needs a reroll ;)

mably’s picture

Not directly related to this issue, but I started implementing my compatibility fix for the prlp module in a new contrib module: https://www.drupal.org/project/password_policy_extras

benstallings made their first commit to this issue’s fork.

benstallings’s picture

Status: Needs work » Needs review
hchonov’s picture

I've opened a follow-up for prlp's password_policy sub-module - #3619057: Password policies not apply to "Forgot password" form