How To Force Strong Passwords in WordPress

Problem/Use Case:

Users may try to set weak passwords, compromising security.

Snippet:

// Force strong passwords
function enforce_strong_passwords($errors, $update, $user) {
    if (!empty($_POST['pass1']) && strlen($_POST['pass1']) < 10) {
        $errors->add('password_too_short', 'Password must be at least 10 characters long.');
    }
}
add_action('user_profile_update_errors', 'enforce_strong_passwords', 10, 3);

Explanation: Forces users to use stronger passwords when updating profiles.

Where to Place It: In functions.php.

Ndifon Luke
Ndifon Luke

Ndifon Luke is the founder & owner of Uncle Luke Digitals—a web design, digital marketing freelancer based in Bamenda, Cameroon. He has over 6 years of expertise in digital marketing and is very passionate about working with clients in achieving their business objectives.