Last active
January 5, 2017 06:42
-
-
Save samhagin/e516736867e58c3c4427 to your computer and use it in GitHub Desktop.
Mass Reset WordPress Passwords
This file contains hidden or 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
#!/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