Skip to content

Instantly share code, notes, and snippets.

@TheLastCicada
Created September 7, 2018 20:34
Show Gist options
  • Save TheLastCicada/97d3fd6d66f0301691b8bce315aeeb60 to your computer and use it in GitHub Desktop.
Save TheLastCicada/97d3fd6d66f0301691b8bce315aeeb60 to your computer and use it in GitHub Desktop.
Enhanced OneLogin Password Fix
<?php
/**
* This script search user with @@@nopass@@@ passwords and replace them by random passwords
*/
add_filter( 'send_password_change_email', '__return_false' );
$users = get_users();
foreach ($users as $user) {
$auth = wp_authenticate($user->user_login, '@@@nopass@@@');
if (!is_wp_error($auth) ) {
$auth->user_pass = wp_generate_password(20, true);
wp_update_user($auth);
echo "User {$auth->ID} updated \n";
} else {
echo "User {$user->ID} doesn't have the bad password \n";
}
}
@TheLastCicada
Copy link
Author

Based on https://gist.github.com/pitbulk/a8223c90a3534e9a7d5e0a93009a094f, this script should be put in the WordPress directory and executed using wp-cli with the command wp eval-file fixpw.php. Improvements over the original include:

  • Disabling of password reset email
  • Output to validate what changes have been made
  • Fixes error regarding HTTP_HOST variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment