Ensure strong passwords for WordPress user accounts to enhance security and protect sensitive information.
add_filter('wp_authenticate', 'codebykp_require_strong_passwords', 10, 2);
function codebykp_require_strong_passwords($user) {
if (isset($_POST['user_pass']) && !preg_match('/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/', $_POST['user_pass'])) {
return new WP_Error('weak_password', __('Password must be at least 8 characters long and include at least one letter and one number.'));
}
return $user;
}