Hello,
i try to adapt the existing code by adding, at the beginning of the method “user_profile_update_errors”, the following lines:
$newpassword= $user->user_pass;
if($newpassword == $user->user_login)
$errors->add( 'pass', __( '<strong>ERROR</strong>: New password cannot be the same as the username.' ), array( 'form-field' => 'pass1' ) );
if($newpassword == $user->user_email)
$errors->add( 'pass', __( '<strong>ERROR</strong>: New password cannot be the same as the email.' ), array( 'form-field' => 'pass1' ) );
if(($c = $this->GetPasswordLen()) != 0)
if(strlen($newpassword) < $c)
$errors->add( 'pass', sprintf(__('<strong>ERROR</strong>: New password must contain at least %d characters.'), $c), array( 'form-field' => 'pass1' ) );
if($this->IsPolicyEnabled(self::POLICY_MIXCASE))
if(strtolower($newpassword) == $newpassword)
$errors->add( 'pass', __( '<strong>ERROR</strong>: New password must contain both uppercase and lowercase characters.' ), array( 'form-field' => 'pass1' ) );
if($this->IsPolicyEnabled(self::POLICY_NUMBERS))
if(!preg_match('/[0-9]/', $newpassword))
$errors->add( 'pass', __( '<strong>ERROR</strong>: New password must contain numbers.' ), array( 'form-field' => 'pass1' ) );
if($this->IsPolicyEnabled(self::POLICY_SPECIAL))
if(!preg_match('/[_\W]/', $newpassword))
$errors->add( 'pass', __( '<strong>ERROR</strong>: New password must contain special characters.' ), array( 'form-field' => 'pass1' ) );
which gives :
public function user_profile_update_errors($errors, $update, $user){
//Tests adapted from the method wp_authenticate_user()
$newpassword= $user->user_pass;
if($newpassword == $user->user_login)
$errors->add( 'pass', __( '<strong>ERROR</strong>: New password cannot be the same as the username.' ), array( 'form-field' => 'pass1' ) );
if($newpassword == $user->user_email)
$errors->add( 'pass', __( '<strong>ERROR</strong>: New password cannot be the same as the email.' ), array( 'form-field' => 'pass1' ) );
if(($c = $this->GetPasswordLen()) != 0)
if(strlen($newpassword) < $c)
$errors->add( 'pass', sprintf(__('<strong>ERROR</strong>: New password must contain at least %d characters.'), $c), array( 'form-field' => 'pass1' ) );
if($this->IsPolicyEnabled(self::POLICY_MIXCASE))
if(strtolower($newpassword) == $newpassword)
$errors->add( 'pass', __( '<strong>ERROR</strong>: New password must contain both uppercase and lowercase characters.' ), array( 'form-field' => 'pass1' ) );
if($this->IsPolicyEnabled(self::POLICY_NUMBERS))
if(!preg_match('/[0-9]/', $newpassword))
$errors->add( 'pass', __( '<strong>ERROR</strong>: New password must contain numbers.' ), array( 'form-field' => 'pass1' ) );
if($this->IsPolicyEnabled(self::POLICY_SPECIAL))
if(!preg_match('/[_\W]/', $newpassword))
$errors->add( 'pass', __( '<strong>ERROR</strong>: New password must contain special characters.' ), array( 'form-field' => 'pass1' ) );
$update = $update; // stops IDE from complaining -_-
if (!$errors->get_error_data('pass') && !$errors->get_error_data('expired_password'))
update_user_option($user->ID, self::OPT_NAME_UPM, time());
}
EDIT: thoses modifications should be added in the file wp-password-policy-manager.php.
And the version of the pulgin is “0.2”