Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Last active September 27, 2023 00:57
Show Gist options
  • Save ipokkel/edf37381f0f67b5184bafb63ec320554 to your computer and use it in GitHub Desktop.
Save ipokkel/edf37381f0f67b5184bafb63ec320554 to your computer and use it in GitHub Desktop.
Change PMPro Strong Password's minimum required password strength.
<?php
/**
* This recipe sets the required password strength or length for PMPro Strong Passwords *
* depending on the PHP version and the settings below.
*
* You should set your password strength or length in the SETTINGS section below
* inside the my_pmprosp_password_strength function.
*
* 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/
*/
// Helper function to set custom password strength or length for PMPro Strong Passwords
function my_pmprosp_password_strength() {
#--- SETTINGS ---#
/*
* 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. ---*/
$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', '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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment