Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change WooCommerce default password security level

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.

like image 586
Husnain Abbas Avatar asked May 10 '17 17:05

Husnain Abbas


2 Answers

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.

like image 143
LoicTheAztec Avatar answered Sep 23 '22 20:09

LoicTheAztec


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;
}
like image 40
codebird Avatar answered Sep 22 '22 20:09

codebird