Last active
October 31, 2020 12:24
-
-
Save rynaldos-zz/e4c34b3f59fe42574eb69435de9fbd04 to your computer and use it in GitHub Desktop.
[WooCommerce 3.0] Require minimum password length for account registration, password update, and password resets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action('woocommerce_process_registration_errors', 'validatePasswordReg', 10, 2 ); | |
function validatePasswordReg( $errors, $user ) { | |
// change value here to set minimum required password chars | |
if(strlen($_POST['password']) < 15 ) { | |
$errors->add( 'woocommerce_password_error', __( 'Password must be at least 15 characters long.' ) ); | |
} | |
// adding ability to set maximum allowed password chars -- uncomment the following two (2) lines to enable that | |
//elseif (strlen($_POST['password']) > 16 ) | |
//$errors->add( 'woocommerce_password_error', __( 'Password must be shorter than 16 characters.' ) ); | |
return $errors; | |
} | |
add_action('woocommerce_save_account_details_errors', 'validateProfileUpdate', 10, 2 ); | |
function validateProfileUpdate( $errors, $user ) { | |
// change value here to set minimum required password chars | |
if(strlen($_POST['password_2']) < 15 ) { | |
$errors->add( 'woocommerce_password_error', __( 'Password must be at least 15 characters long.' ) ); | |
} | |
// adding ability to set maximum allowed password chars -- uncomment the following two (2) lines to enable that | |
//elseif (strlen($_POST['password_2']) > 16 ) | |
//$errors->add( 'woocommerce_password_error', __( 'Password must be shorter than 16 characters.' ) ); | |
return $errors; | |
} | |
add_action('woocommerce_password_reset', 'validatePasswordReset', 10, 2 ); | |
function validatePasswordReset( $errors, $user ) { | |
// change value here to set minimum required password chars -- uncomment the following two (2) lines to enable that | |
if(strlen($_POST['password_3']) < 15 ) { | |
$errors->add( 'woocommerce_password_error', __( 'Password must be at least 15 characters long.' ) ); | |
} | |
// adding ability to set maximum allowed password chars -- uncomment the following two (2) lines to enable that | |
//elseif (strlen($_POST['password_3']) > 16 ) | |
//$errors->add( 'woocommerce_password_error', __( 'Password must be shorter than 16 characters.' ) ); | |
return $errors; | |
} | |
add_action( 'woocommerce_after_checkout_validation', 'minPassCharsCheckout', 10, 2 ); | |
function minPassCharsCheckout( $user ) { | |
// change value here to set minimum required password chars on checkout page account registration | |
if ( strlen( $_POST['account_password'] ) < 15 ) { | |
wc_add_notice( __( 'Password must be at least 15 characters long.', 'woocommerce' ), 'error' ); | |
} | |
} | |
// Did this help? Donate me some BTC: 1BEsm8VMkYhSFJ92cvUYwxCtsfsB2rBfiG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@bobafett92. this is to create a minimum requirement. you would need to change the logic to do what you want.