WordPress: Add new Useraccount without access to the backend with only FTP


Suppose you have lost your password to your wordpress website. Resetting the password is not an option because you don’t have access to the emailaddress.

Your website is not lost yet as long as you still have access to the server. There are two easy ways to get a new password / useraccount. The first one involves changing the database and I described it here.

The other one would be to make some changes to the functions.php which automatically insert a new user-account that you can use to recover your website. For this method you need FTP-Access or some other method to alter the functions.php file of your current theme.

Adding the necessary code to create a new account

First open the functions.php of your active theme. You will find your themes in the folder wp-content/themes

All the way at the bottom of the file add the following code:

function nddt_admin_account(){
  $user = 'NDDT';
  $pass = 'password';
  $email = '[email protected]';
  if (!username_exists($user)  && !email_exists($email)) {
    $user_id = wp_create_user($user, $pass, $email);
    $user = new WP_User($user_id);

You can of course replace the username, password and email with your own. Just make sure it isn’t used in the website yet.

The code will check of an account with this username and password already exists and if it doesn’t this account will be added.

Just go back to the page and refresh it once (Ctrl-R) so that the code is executed. Then go the wp-admin and log in.

Clean up

Don’t forget to delete the code after revocering your website. You shoud probaply also clean up your user accounts.


This code can also be used as a backdoor for websites that you don’t want to loose access to. Maybe a businesspartner or a client that u dont trust. Instead of executing it everytime you could only execute it when a secret route is called.

Keep in mind that this might be illegal in your country.

If you need any help leave me a comment.


Please enter your comment!
Please enter your name here