File: /home/httpd/html/perfectpanties.com/old.public_html/reset.pass
#!/bin/sh
#
# Given a wp-config.php, will attempt to reset the administrator
# password in the database.
#
WPCONFIG="$1"
if [ ! -e "$WPCONFIG" ]
then
echo Please provide the wp-config.php filename
fi
# Generate a random one or set a static one
NEWPASS=`mkpasswd -s 0`
#NEWPASS="cDb8zmIe1"
DBNAME=`grep DB_NAME $WPCONFIG|cut -f2 -d','|cut -f1 -d')'|tr -d "\'"|tr -d ' '`
DBUSER=`grep DB_USER $WPCONFIG|cut -f2 -d','|cut -f1 -d')'|tr -d "\'"|tr -d ' '`
DBPASS=`grep DB_PASSWORD $WPCONFIG|cut -f2 -d','|cut -f1 -d')'|tr -d "\'"|tr -d ' '`
DBHOST=`grep DB_HOST $WPCONFIG|cut -f2 -d','|cut -f1 -d')'|tr -d "\'"|tr -d ' '`
#echo "DBNAME: $DBNAME "
#echo "DBUSER: $DBUSER "
#echo "DBPASS: $DBPASS "
#echo "DBHOST: $DBHOST "
CRED="-u$DBUSER -p$DBPASS -h$DBHOST $DBNAME -bNr "
# Get the ID we're going to update
ID=`mysql $CRED -e "SELECT ID from wp_users where user_login = '7296663ramond'"`
if [ "x$ID" = "x" ]
then
echo "ERROR: could not find the admin user"
exit
fi
#echo Found ID: $ID
OLDPASS=`mysql $CRED -e "SELECT user_pass from wp_users where ID=$ID"`
echo OLD Password for ID $ID = $OLDPASS >> /var/log/wpreset.log
echo mysql $CRED -e "UPDATE wp_users SET user_pass=MD5('$NEWPASS') where ID=$ID" >>/var/log/wpreset.log
mysql $CRED -e "UPDATE wp_users SET user_pass=MD5('$NEWPASS') where ID=$ID" >>/var/log/wpreset.log
if [ $? -eq 0 ]
then
echo Updated admin password for $DBNAME to $NEWPASS | tee -a /var/log/wordpress.log
fi