Home > stuff > Changing Wordpress default admin user name

Changing Wordpress default admin user name

February 8th, 2009

If an attacker knows your administrator user name all he needs to do is to guess your password to get in to your system. Wordpress default administrator user is named ‘admin’ and you cant rename it using the WP management panel which makes Wordpress blogs with weak passwords extremely vulnerable, and eventually every password is weak.

You can go into the MySQL database and change the login name of the administrator account to whatever you like.
First backup your database then open up phpMyAdmin and select your Wordpress database, from there select the wp_users table and click the browse tab.
Locate the line with ID set to 1, you can see that the user_login column is set to ‘admin’. Using the Edit tool (Pencil icon) change the user_login (And nothing else) to your desired login name and save your changes.

That’s it, you are now able to log in to your blog as administrator with your unique user name.

Advanced Users:
Instead of browsing through tables and web interfaces you can run this line from your MySQL console of choice, modify the NewLogInName value to your desired login and execute.

UPDATE `wp_users` SET `user_login` = ‘NewLogInName‘ WHERE `wp_users`.`ID` =1 LIMIT 1 ;

PHP script:
This script will change the admin username for you, edit it and set your desired administrator username. Upload it to the Wordpress home directory and run it.
Make sure you delete the file from the server when you’re done.


<?php

/*
Changing the Wordpress administrator username.
http://www.aviran.org
*/

$NewAdminUserName="Aviran";
include("wp-config.php");
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link)
   die('Could not connect: ' . mysql_error());

if(!mysql_db_query(DB_NAME, "UPDATE wp_users SET user_login='$NewAdminUserName' WHERE wp_users.ID=1 LIMIT 1"))
   echo "Error. Could not change administrator username.";

echo "Username changed successfully";
mysql_close($link);
?>

aviran stuff

  1. May 13th, 2009 at 21:25 | #1

    I love it! That is way cool man! The steps weren’t that complicated too, which is great.

  2. May 16th, 2009 at 18:39 | #2

    Thanks, this is very helpful.

    I’m using WP for many customers and I’m wondering whether I could rewrite the Wordpress script, so the name ‘admin’ wouldn’t even be installed in the first place but some other default name like ’superuser’. I’m not an PHP expert though, so I’d appreciate your thoughts on that.

    Thanks again!

  3. May 16th, 2009 at 21:25 | #3

    I would not recommend modifying the Wordpress code in order to do that, you have to consider that you will need to repeat the process when a new version comes out.
    Instead you should use an external script or a plugin, I dont think there’s a pluging out there (I’ll just have to write one when I’ll find the time) so here’s a small script that changes the admin user name to whatever you like. Just upload the file (Edit it first) to the Wordpress home directory and run it, then delete it.

    (The script has been added to the post)

  4. May 17th, 2009 at 19:32 | #4

    @aviran

    Many thanks! This is beautiful! Works like a charm, and makes my life so much easier!

    You’re my hero :o).

  5. November 22nd, 2009 at 16:35 | #5
  1. No trackbacks yet.