How can we help?

Search for answers or browse our knowledge base.

Table of Contents

How to enforce strong password policies during user registration

In this article, we explain how you can enforce strong password security policies during the user registration process since Melapress Login Security is able to validate the passwords of users who do not have a user role yet.

Which password policies apply to users without a role?

When configuring password policies with the Melapress Login Security plugin, you start by configuring a site-wide policy that applies to all the users on the website. If you require different policies for users with specific user roles, you can configure different password policies for users with that WordPress user role.

The site-wide password policy configured in the Site-wide policies tab also applies to users who do not have a user role, for example, users registering on your website.

Implementing password validation during user registration

We will be illustrating this with an example; we will be using the User Registration plugin to showcase how to validate passwords in a user registration custom form. Of course, this is just an example, and the process can be adapted to other plugins.

Here is the code in full. We will examine and explain it further below:

add_action( 'user_registration_validate_user_pass','wpassword_validate_text_field',10,4);
  
function wpassword_validate_text_field($single_form_field, $data, $filter_hook, $form_id) {
     $field_label = isset( $data->label ) ? $data->label : '';
     $value = isset( $data->value ) ? $data->value : '';
  
     $ppm = ppm_wp();
     $pwd_check = new \PPMWP\PPM_WP_Password_Check();
     $does_violate_rules = $pwd_check->does_violate_rules( $value, true );
     $issues_found = '';
  
     if ( $does_violate_rules ) {
          $error_strings = $ppm->msgs->error_strings;
          foreach ( $does_violate_rules as $violation => $value ) {
               $issues_found .= $error_strings[ $violation ] .'';
          }
}
  
     if( $does_violate_rules ) {
          add_filter( $filter_hook, function ( $msg ) use ( $issues_found ) {
               return __( $issues_found, 'user-registration' );
          });
     }
}

Code explanation

The main logic is executed in the wpassword_validate_text_field() function. First we take the new password that has been submitted through the form and check if its violates any of the configured policies using the following:

$pwd_check-gt;does_violate_rules( $value, true );

If the password the user submitted does not meet the configured password policy, the code creates an error string which is returned to the user, explaining in detail the reasons why the password was not accepted. An example of this is illustrated in the below screenshot:

User is prompted with details if the password does not meet the configured policies

The survey results are in: Find out what your WordPress security gameplan might be missing

Uploading Melapress Login Security as a zip file in WordPress
Melapress Login Security in the WordPress plugin repository
Close

Installing Melapress Login Security Free

Congratulations on taking control of your WordPress website's security by implementing robust login and password policies with Melapress Login Security. You can change your login page URL, limit failed login attempts, and reset passwords.

 

Below are two ways to install Melapress Login Security on your website:

Go to your plugin dashboard on your site, then go to "Add New" and then search for Melapress Login Security.

Download the Melapress Login Security plugin zip, then select upload in your plugin dashboard under "Add New".

OPTION 1

OPTION 2

Uploading CAPTCHA 4WP as a zip file in WordPress
CAPTCHA 4WP in the WordPress plugin repository
Close

Installing CAPTCHA 4WP Free

Well done you. You're one step closer to safeguarding your WordPress website from spam and automated attacks with CAPTCHA 4WP. You'll be able to effortlessly integrate CAPTCHA into your forms and enjoy a website with enhanced security.

 

Below are two ways to install CAPTCHA 4WP on your website:

Go to your plugin dashboard on your site, then go to "Add New", and then search for CAPTCHA 4WP.

Download the CAPTCHA 4WP plugin zip, then select upload in your plugin dashboard under "Add New".

OPTION 1

OPTION 2

Uploading WP Activity Log as a zip file in WordPress
WP Activity Log in the WordPress plugin repository
Close

Installing WP Activity Log Free on your website

You deserve a pat on the back for choosing to record user actions and changes on your website. That is the first step towards better user accountability, easier troubleshooting of website security, and many other benefits of issues.

 

Below are the two ways to install WP Activity Log on your website:

Go to your plugin dashboard on your site, then go to "Add New" and then search for WP Activity Log.

Download the WP Activity Log plugin zip, then select upload in your plugin dashboard under "Add New".

OPTION 1

OPTION 2

Uploading WP 2FA as a zip file in WordPress
WP 2FA in the WordPress plugin repository
Close

Installing WP 2FA Free

Congratulations on taking the first step towards enhancing your WordPress site's security with WP 2FA Free! You're now on your way to protecting your valuable data and ensuring peace of mind. No coding or technical knowledge is required.

 

Below are two ways to install WP 2FA on your website:

Go to your plugin dashboard on your site, then go to "Add New", and then search for WP 2FA.

Download the WP 2FA plugin zip, then select upload in your plugin dashboard under "Add New".

OPTION 1

OPTION 2