Skip to content

Added password strength checker class and Sync listener.#11643

Merged
kraftbj merged 11 commits intomasterfrom
add/password-strength-checker
Mar 26, 2019
Merged

Added password strength checker class and Sync listener.#11643
kraftbj merged 11 commits intomasterfrom
add/password-strength-checker

Conversation

@zinigor
Copy link
Copy Markdown
Contributor

@zinigor zinigor commented Mar 21, 2019

This adds a class that listens to password verification events and checks the passwords for certain criteria.

Changes proposed in this Pull Request:

  • Adds a password checker class.
  • Adds a new Sync listener warning for insecure passwords.

Testing instructions:

  • Use a Jetpack site with this PR.
  • Sandbox your connection and apply D25323-code to your sandbox.
  • Set an insecure password for your user, for example, the same as your login.
  • Observe an audit log entry and a sticker in the MC.

Proposed changelog entry for your changes:

  • Added a password checker class.

zinigor added 2 commits March 21, 2019 18:27
As an accompanying code, also added the password strength checker library.
@zinigor zinigor added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review This PR is ready for review. [Package] Sync labels Mar 21, 2019
@zinigor zinigor added this to the 7.2 milestone Mar 21, 2019
@zinigor zinigor self-assigned this Mar 21, 2019
@zinigor zinigor requested review from a team, dereksmart and jhnstn March 21, 2019 17:09
@jetpackbot
Copy link
Copy Markdown
Collaborator

jetpackbot commented Mar 21, 2019

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: April 2, 2019.
Scheduled code freeze: March 26, 2019

Generated by 🚫 dangerJS against 23e476b

return $user;
}

call_user_func(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing this.
I think it would be cleared to do a

do_action( 'jetpack_password_check_failed', $user->ID, $test_results['test_results']['failed'] );

and then in listeners we can then just call

add_action( 'jetpack_password_check_failed', $this->handler,  10, 2 );

*/

class WP_Test_Jetpack_Sync_Module_Auth extends WP_Test_Jetpack_Sync_Base {

Copy link
Copy Markdown
Member

@enejb enejb Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ Thanks for adding the tests

@enejb
Copy link
Copy Markdown
Member

enejb commented Mar 21, 2019

I am not 100% since I haven't tested this but it looks like authenticate filter is called on every login as well. Which is not some that we want.

I think it would be really interesting to always send an event when the user password changes.
and if they change the password to something that is not secure also send that as extra data with the error that we do want.

@kraftbj
Copy link
Copy Markdown
Contributor

kraftbj commented Mar 21, 2019

I am not 100% since I haven't tested this but it looks like authenticate filter is called on every login as well. Which is not some that we want.

At least use wp_authenticate_user instead?

I think it would be really interesting to always send an event when the user password changes.
and if they change the password to something that is not secure also send that as extra data with the error that we do want.

Of interest:

/**
	 * Fires before the password and confirm password fields are checked for congruity.
	 *
	 * @since 1.5.1
	 *
	 * @param string $user_login The username.
	 * @param string $pass1     The password (passed by reference).
	 * @param string $pass2     The confirmed password (passed by reference).
	 */
	do_action_ref_array( 'check_passwords', array( $user->user_login, &$pass1, &$pass2 ) );

I think that may be the only place we can access a changing password before it is hashed when an user is inserted/updated.

@kraftbj kraftbj added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Mar 21, 2019
@@ -0,0 +1,1288 @@
<?php //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @zinigor I added these ignore statements to the new files and added them to the phpcs whitelist since they're new and clean.

} else {
$this->user_id = $user;
}
$this->min_password_length = apply_filters( 'better_password_min_length', $this->min_password_length );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs docblock and likely changed hook name to jetpack_password_checker, etc

}

/**
* Filters Jetpack's password strength enforcement settings. You can modify the minimum
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could include in the docs that 28 is weak, 32 is suggested, etc?

@kraftbj kraftbj added [Status] In Progress and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Mar 22, 2019
@matticbot
Copy link
Copy Markdown
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello zinigor! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D25993-code before merging this PR. Thank you!

enejb added 2 commits March 25, 2019 16:06
Only call clear_flags when we after we acually use the flags.
We had an issue where we were cleading the flags after login in before we could acually use the flags.
@matticbot
Copy link
Copy Markdown
Contributor

zinigor, Your synced wpcom patch D25993-code has been updated.

@enejb
Copy link
Copy Markdown
Member

enejb commented Mar 26, 2019

I tested this and it works as expected for me.

When I login as a user on my jetpack site as that has a week password. I can see the event come though on the .com side.

the code on .com will need have this PR applied to it.
D25997-code

@matticbot
Copy link
Copy Markdown
Contributor

zinigor, Your synced wpcom patch D25993-code has been updated.

@kraftbj kraftbj added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Mar 26, 2019
@matticbot
Copy link
Copy Markdown
Contributor

zinigor, Your synced wpcom patch D25993-code has been updated.

@kraftbj kraftbj added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Mar 26, 2019
@kraftbj kraftbj merged commit 0088971 into master Mar 26, 2019
@kraftbj kraftbj deleted the add/password-strength-checker branch March 26, 2019 14:39
@ghost ghost removed [Status] Needs Changelog [Status] Ready to Merge Go ahead, you can push that green button! labels Mar 26, 2019
kraftbj added a commit that referenced this pull request Mar 26, 2019
kraftbj added a commit that referenced this pull request Mar 27, 2019
* Initial Changelog for 7.2

* Testing list: add mention of IE11 testing

* Initial Changelog for 7.2

* Testing list: add mention of IE11 testing

* Add CL for #11224

* Add CL for #11426

* Add CL for #11442

* Add testing instructions for #11224

* Add CL for #11451

* Reclassify CL item

* Add testing instructions for #11451

* Add CL for #11486

* Add CL for #11418

* Add CL for #11524

* Add CL and testing instructions for #11449

* Add CL for #11460

* Add CL for #11520 and #11582

* Add CL for #11531

* Add CL #11644

* Add testing instructions for #11644

* Add testing instructions for #11644

* Add CL for #11618

* Uniform changelog lines

* CL #11679

* CL #11661

* CL #11654

* CL #11645

* CL #11643

* CL #11636

* CL #11635 and for other PHPCS commits

* CL #11627

* CL #11626

* CL #11598

* CL #11596

* Remove nested items for shortcopy. I don't believe the detailed list is helpful

* CL #11570

* CL #11569

* CL #11560

* CL #11558

* CL #11555

* CL #6704

* CL #11298

* CL #11324

* CL #11443

* CL #11484

* CL #11516

* CL #11529

* Expand Ads block enhancement CL item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Package] Sync Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants