-
-
Save michaelbeil/da7cd0318c8283869ea39b7350525f65 to your computer and use it in GitHub Desktop.
Change the required password length to 8 for Require Strong Passwords
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // Do NOT copy this line | |
/** | |
* Change pmpro-strong-passwords to require a minimum of 8 characters. | |
*/ | |
add_filter( 'pmpro_registration_checks', 'my_pmpro_strong_password_check' ); | |
function my_pmpro_strong_password_check( $pmpro_continue_registration ) { | |
// Don't load this script at all if user is logged in. | |
if ( is_user_logged_in() ) { | |
return $pmpro_continue_registration; | |
} | |
//only bother checking if there are no errors so far | |
if ( ! $pmpro_continue_registration ) { | |
return $pmpro_continue_registration; | |
} | |
$username = $_REQUEST['username']; | |
$password = $_REQUEST['password']; | |
// no password (existing user is checking out) | |
if ( empty( $password ) ) { | |
return $pmpro_continue_registration; | |
} | |
// Check for length (5 characters) | |
if ( strlen( $password ) < 5 ) { | |
pmpro_setMessage( esc_html__( 'Your password must be at least 8 characters long.', 'pmpro-strong-passwords' ), 'pmpro_error' ); | |
return false; | |
} | |
// Check for username match | |
if ( $password == $username ) { | |
pmpro_setMessage( esc_html__( 'Your password must not match your username.', 'pmpro-strong-passwords' ), 'pmpro_error' ); | |
return false; | |
} | |
// Check for containing username | |
if ( strpos( $password, $username ) !== false ) { | |
pmpro_setMessage( esc_html__( 'Your password must not contain your username.', 'pmpro-strong-passwords' ), 'pmpro_error' ); | |
return false; | |
} | |
// Check for lowercase | |
if ( ! preg_match( '/[a-z]/', $password ) ) { | |
pmpro_setMessage( esc_html__( 'Your password must contain at least 1 lowercase letter.', 'pmpro-strong-passwords' ), 'pmpro_error' ); | |
return false; | |
} | |
// Check for uppercase | |
if ( ! preg_match( '/[A-Z]/', $password ) ) { | |
pmpro_setMessage( __( 'Your password must contain at least 1 uppercase letter.', 'pmpro-strong-passwords' ), 'pmpro_error' ); | |
return false; | |
} | |
// Check for numbers | |
if ( ! preg_match( '/[0-9]/', $password ) ) { | |
pmpro_setMessage( esc_html__( 'Your password must contain at least 1 number.', 'pmpro-strong-passwords' ), 'pmpro_error' ); | |
return false; | |
} | |
// Check for special characters | |
if ( ! preg_match( '/[\W]/', $password ) ) { | |
pmpro_setMessage( esc_html__( 'Your password must contain at least 1 special character.', 'pmpro-strong-passwords' ), 'pmpro_error' ); | |
return false; | |
} | |
// If we've passed all of the above, return the current continue registration flag. | |
return $pmpro_continue_registration; | |
} | |
add_action( 'init', 'switch_my_pmpro_password_notice' ); | |
function switch_my_pmpro_password_notice() { | |
if ( has_filter( 'pmpro_checkout_after_password', 'pmprosp_pmpro_checkout_after_password' ) ) { | |
remove_filter( 'pmpro_checkout_after_password', 'pmprosp_pmpro_checkout_after_password', 1 ); | |
add_filter( 'pmpro_checkout_after_password', 'my_pmprosp_pmpro_checkout_after_password', 1 ); | |
} | |
} | |
function my_pmprosp_pmpro_checkout_after_password() { | |
?> | |
<div id="pmprosp-container"></div> | |
<?php | |
echo '<small id="pmprosp-password-notice">Note: A good password is at least 8 characters long and contains upper and lowercase letters, a number, and a special character</small>'; | |
wp_localize_script( | |
'password-strength-meter', | |
'pwsL10n', | |
array( | |
'empty' => _x( 'Strength indicator', 'password strength', 'pmpro-strong-passwords' ), | |
'short' => _x( 'Very weak', 'password strength', 'pmpro-strong-passwords' ), | |
'bad' => _x( 'Weak', 'password strength', 'pmpro-strong-passwords' ), | |
'good' => _x( 'Medium', 'password strength', 'pmpro-strong-passwords' ), | |
'strong' => _x( 'Strong', 'password strength', 'pmpro-strong-passwords' ), | |
'mismatch' => _x( 'Mismatch', 'password strength', 'pmpro-strong-passwords' ), | |
'password_tooltip' => _x( 'Note: A good password is at least 8 characters long and contains upper and lowercase letters, a number, and a special character', 'password tooltip displayed on hover over question mark next to password field label', 'pmpro-strong-passwords' ), | |
'progressbar_bg_color' => apply_filters( 'pmprosp_progressbar_bg_color', '#aaaaaa' ), | |
'display_progressbar' => apply_filters( 'pmprosp_display_progressbar', true ), | |
'display_password_strength' => apply_filters( 'pmprosp_display_password_strength', true ), | |
'display_password_tooltip' => apply_filters( 'pmprosp_display_password_tooltip', true ), | |
'password_blacklist' => json_encode( apply_filters( 'pmprosp_password_blocklist', array( 'admin', 'administrator', '@dministrator', '@dmin', 'test', 'tester' ) ) ), | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment