Skip to content

Instantly share code, notes, and snippets.

@scottsousa
Created August 5, 2013 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottsousa/6156641 to your computer and use it in GitHub Desktop.
Save scottsousa/6156641 to your computer and use it in GitHub Desktop.
Force a user to use strong passwords in Paid Memberships Pro. This plugin checks for length, matching/containing username, lowercase/uppercase, numbers, and special characters
<?php
/*
Plugin Name: PMPro Strong Passwords
Version: 0.1
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/
Description: Force users to submit strong passwords.
Version: .1
Author: Scott Sousa
Author URI: http://slocumstudio.com
*/
/**
* This function checks to make sure the user has submitted a strong password
* by checking for length, lowercase/uppercase, numbers, special characters, and matching username.
*/
add_filter( 'pmpro_registration_checks', 'pmpro_strong_password_check' );
function pmpro_strong_password_check( $pmpro_continue_registration ) {
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
// Check for length (8 characters)
if ( strlen( $password ) < 8 ) {
pmpro_setMessage( 'Your password must be at least 8 characters long.', 'pmpro_error' );
return false;
}
// Check for username match
if ( $password == $username ) {
pmpro_setMessage( 'Your password must not match your username.', 'pmpro_error' );
return false;
}
// Check for containing username
if ( strpos( $password, $username ) !== false ) {
pmpro_setMessage( 'Your password must not contain your username.', 'pmpro_error' );
return false;
}
// Check for lowercase
if ( ! preg_match( '/[a-z]/', $password ) ) {
pmpro_setMessage( 'Your password must contain at least 1 lowercase letter.', '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_error' );
return false;
}
// Check for numbers
if ( ! preg_match( '/[0-9]/', $password ) ) {
pmpro_setMessage( 'Your password must contain at least 1 number.', 'pmpro_error' );
return false;
}
// Check for special characters
if ( ! preg_match( '/[\W]/', $password ) ) {
pmpro_setMessage( 'Your password must contain at least 1 special character.', 'pmpro_error' );
return false;
}
// If we've passed all of the above, return the current continue registration flag.
return $pmpro_continue_registration;
}
@vmavrikios
Copy link

Hi..

As described, this fits exactly what I wanted to do with Paid Memberships Pro on my WP site.
But, I only have a basic understanding of how these things work...
To be more precise ...I don't know how to use the above file so it will work with the plugin and the theme I am using.

Could you please advice on how to implement the above code?

Kind thanks,

Vas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment