Skip to content

Instantly share code, notes, and snippets.

@samhagin
Last active January 5, 2017 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samhagin/e516736867e58c3c4427 to your computer and use it in GitHub Desktop.
Save samhagin/e516736867e58c3c4427 to your computer and use it in GitHub Desktop.
Mass Reset WordPress Passwords
#!/bin/bash
# Get all users from the database
users=$(mysql -u <user> -p<password> <dbname> -Bse "select user_login from wp_users")
# put the users in an array
array=( $users )
# for loop to set a random password, get the users email address, reset the password and send an email with the new password
for user in "${array[@]}"
do
# set random password
password=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 12 | head -n 1)
# reset password to random password
mysql -u <user> -p<password> <dbname> -e "update wp_users set user_pass = md5('$password') where user_login='$user'"
# get user email address
email=$(mysql -u <user> -p<password> <dbname> -Bse "select user_email from wp_users where user_login='$user'")
# body of email message
message="Your password for http://example.com/wp-admin has been reset, please login with the following\n\n $user \n $password"
# send the email
echo -e $message | mail -s "Example.com Password Reset" $email
# echo the username and password back to the shell
echo $user $password
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment