Change WooCommerce default password security level
Asked Answered
F

4

15

I am trying to change the WooCommerce Registration form minimum password strength and I am unable to do much.

Can anyone please share a solution by which I can amend the minimum password strength and allow users to user a password that's 7 characters long and does not need any symbols or capital letters inside it?

Thanks.

Filberto answered 10/5, 2017 at 17:36 Comment(0)
R
32

The only existing hook setting for that is woocommerce_min_password_strength filter hook. So you can set a custom hook function and lowering this strenght. There is 4 possible settings:

  • 3 => Strong (default)
  • 2 => Medium
  • 1 => Weak
  • 0 => Very Weak (anything).

Here is that code:

add_filter( 'woocommerce_min_password_strength', 'reduce_min_strength_password_requirement' );
function reduce_min_strength_password_requirement( $strength ) {
    // 3 => Strong (default) | 2 => Medium | 1 => Weak | 0 => Very Weak (anything).
    return 2; 
}

Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and works.

All other solutions will be complicated and a real development.

Rem answered 10/5, 2017 at 18:54 Comment(3)
thank you for your help. I used some javaascript to fix the issue since I needed to a very specific password criteria. thanks for your help!Filberto
@HusnainAbbas You should add an update to your question or directly as an answer with that code and some explanations. This will be useful for the community. Thanks.Rem
Note: Contrary to the default hint verbiage, there is NOT a required number or type of characters that correspond to each security level. It is controlled by an open source, pattern-matching algorithm called 'zxcvbn' developed by Dropbox. Link: github.com/dropbox/zxcvbnEmmy
S
12

The answer above by @LoicTheAztec works perfectly and is very clear. I'm adding this answer because I'm not sure it's correct to put additional suggestions and code in a comment (sorry if I'm not following proper StackOverflow protocols -- someone please let me know if that's the case!).

Anyway even after changing the password strength requirement I was still seeing the very stern and rather unhelpful password hint demanding twelve characters &c., so I went looking for a way to change that. Here are the two functions I've got running and they're working just as expected.

For the password hint function, thanks to arjenlentz.

// First, change the required password strength
add_filter( 'woocommerce_min_password_strength', 'reduce_min_strength_password_requirement' );
function reduce_min_strength_password_requirement( $strength ) {
    // 3 => Strong (default) | 2 => Medium | 1 => Weak | 0 => Very Weak (anything).
    return 2; 
}

// Second, change the wording of the password hint.
add_filter( 'password_hint', 'smarter_password_hint' );
function smarter_password_hint ( $hint ) {
    $hint = 'Hint: longer is stronger, and consider using a sequence of random words (ideally non-English).';
    return $hint;
}
Salvo answered 22/9, 2019 at 0:42 Comment(0)
Q
3

FYI, that code did not work for me to lower the password requirements. I tried a couple other codes but to no avail. I ended up using this code below to simply remove the password requirement check.

function iconic_remove_password_strength() {
    wp_dequeue_script( 'wc-password-strength-meter' );
}
add_action( 'wp_print_scripts', 'iconic_remove_password_strength', 10 );

Taken from here: https://iconicwp.com/blog/disable-password-strength-meter-woocommerce/

Quiteris answered 31/12, 2018 at 22:25 Comment(1)
Yes the meter was blocking me on the reset password pageMatrimonial
A
0

An example to convert the Weak indicator to Medium and to remove the hint for Weak.

Add this to functions.php

/* Reduce Password Strength
==================================================================================================== */
function custom_woocommerce_min_password_strength($strength) {
    return 1; // Change to desired strength level (0, 1, 2, 3)
}
add_filter('woocommerce_min_password_strength', 'custom_woocommerce_min_password_strength');


/* Change Weak indicator to Medium and Remove Weak Hint
==================================================================================================== */
function custom_enqueue_woocommerce_password_script() {
    wp_enqueue_script('wc-password-strength-meter');
    wp_add_inline_script('wc-password-strength-meter', "
        jQuery(document).ready(function($) {
            $('body').on('change keyup', 'input[type=password]', function(){
                var passBox = $('.woocommerce-password-strength');
                var passHint = $('.woocommerce-password-hint');
                var passStrength = passBox.text();
                if (passStrength.indexOf('Weak') >= 0) {
                    passBox.removeClass('bad').addClass('good');
                    passBox.text('Medium'); // Change the text
                    passHint.hide(); // Hide the hint
                } else {
                    passHint.show(); // Show the hint otherwise
                }
            });
        });
    ");
}
add_action('wp_enqueue_scripts', 'custom_enqueue_woocommerce_password_script');
Abagail answered 19/8, 2024 at 8:17 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.