Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.