Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Last active September 27, 2023 00:57
Show Gist options
  • Select an option

  • Save ipokkel/edf37381f0f67b5184bafb63ec320554 to your computer and use it in GitHub Desktop.

Select an option

Save ipokkel/edf37381f0f67b5184bafb63ec320554 to your computer and use it in GitHub Desktop.

Revisions

  1. ipokkel revised this gist Apr 8, 2022. 1 changed file with 51 additions and 11 deletions.
    62 changes: 51 additions & 11 deletions change-pmprosp-required-password-strength.php
    Original file line number Diff line number Diff line change
    @@ -1,27 +1,67 @@
    <?php
    /**
    * This recipe sets the required password strength for PMPro Strong Passwords.
    * This recipe sets the required password strength or length for PMPro Strong Passwords *
    * depending on the PHP version and the settings below.
    *
    * 1 is somewhat guessable (guesses < 10^8), provides some protection from unthrottled online attacks
    * 2 is safely unguessable (guesses < 10^10), offers moderate protection from offline slow-hash scenario
    * 3 is very unguessable (guesses >= 10^10) and provides strong protection from offline slow-hash scenario
    * You should set your password strength or length in the SETTINGS section below
    * inside the my_pmprosp_password_strength function.
    *
    * Default strength is 2.
    * You can add this recipe to your site by creating a custom plugin
    * or using the Code Snippets plugin available for free in the WordPress repository.
    * Read this companion article for step-by-step directions on either method.
    * https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
    */
    function my_pmprosp_minimum_password_score( $min_strength, $password_strength ) {

    // Helper function to set custom password strength or length for PMPro Strong Passwords
    function my_pmprosp_password_strength() {

    #--- SETTINGS ---#

    // Set minimum password strength
    /*
    * Set minimum password strength ( Requires PHP 7.2 or higher )
    *
    * 1 is somewhat guessable (guesses < 10^8), provides some protection from unthrottled online attacks
    * 2 is safely unguessable (guesses < 10^10), offers moderate protection from offline slow-hash scenario
    * 3 is very unguessable (guesses >= 10^10) and provides strong protection from offline slow-hash scenario
    *
    * Default strength is 2.
    */
    $min_strength = 3;

    /*
    * Set minimum required password characters ( if PHP version is lower than 7.2 )
    *
    * Default length is 12.
    */
    $minimum_password_length = 16;

    /*--- That's it, no further editing required. ---*/

    // reset to the default WP strength if minimum strength is not 1, 2, or 3.
    if ( ! in_array( $min_strength, array( 1, 2, 3 ), true ) ) {
    $min_strength = 2;
    $password_strength = version_compare( phpversion(), '7.2', '<' ) ? (int) $minimum_password_length : (int) $min_strength;

    return $password_strength;
    }

    function set_pmprosp_minimum_password_score( $min_strength, $password_strength ) {
    // Bail if function is missing or password strength not set correctly.
    if ( ! function_exists( 'my_pmprosp_password_strength' ) || ! in_array( my_pmprosp_password_strength(), array( 1, 2, 3 ), true ) ) {
    return $min_strength;
    }

    $min_strength = my_pmprosp_password_strength();

    return $min_strength;
    }
    add_filter( 'pmprosp_minimum_password_score', 'my_pmprosp_minimum_password_score', 10, 2 );
    add_filter( 'pmprosp_minimum_password_score', 'set_pmprosp_minimum_password_score', 10, 2 );

    function set_pmprosp_minimum_password_length( $minimum_length ) {
    // Bail if function is missing or reset length to default if custom length is zero or smaller.
    if ( ! function_exists( 'my_pmprosp_password_strength' ) || 0 >= my_pmprosp_password_strength() ) {
    return $minimum_length;
    }

    $minimum_length = my_pmprosp_password_strength();

    return $minimum_length;
    }
    add_filter( 'pmprosp_minimum_password_length', 'set_pmprosp_minimum_password_length' );
  2. ipokkel revised this gist Apr 8, 2022. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions change-pmprosp-required-password-strength.php
    Original file line number Diff line number Diff line change
    @@ -10,13 +10,18 @@
    */
    function my_pmprosp_minimum_password_score( $min_strength, $password_strength ) {

    // Set password strenght between 1 and 3
    #--- SETTINGS ---#

    // Set minimum password strength
    $min_strength = 3;

    // reset to default strength if out of range/
    if ( $min_strength < 1 || $min_strength > 3 ) {
    /*--- That's it, no further editing required. ---*/

    // reset to the default WP strength if minimum strength is not 1, 2, or 3.
    if ( ! in_array( $min_strength, array( 1, 2, 3 ), true ) ) {
    $min_strength = 2;
    }

    return $min_strength;
    }
    add_filter( 'pmprosp_minimum_password_score', 'my_pmprosp_minimum_password_score', 10, 2 );
  3. ipokkel created this gist Mar 15, 2021.
    22 changes: 22 additions & 0 deletions change-pmprosp-required-password-strength.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    <?php
    /**
    * This recipe sets the required password strength for PMPro Strong Passwords.
    *
    * 1 is somewhat guessable (guesses < 10^8), provides some protection from unthrottled online attacks
    * 2 is safely unguessable (guesses < 10^10), offers moderate protection from offline slow-hash scenario
    * 3 is very unguessable (guesses >= 10^10) and provides strong protection from offline slow-hash scenario
    *
    * Default strength is 2.
    */
    function my_pmprosp_minimum_password_score( $min_strength, $password_strength ) {

    // Set password strenght between 1 and 3
    $min_strength = 3;

    // reset to default strength if out of range/
    if ( $min_strength < 1 || $min_strength > 3 ) {
    $min_strength = 2;
    }
    return $min_strength;
    }
    add_filter( 'pmprosp_minimum_password_score', 'my_pmprosp_minimum_password_score', 10, 2 );