How to Restore OwnCloud Password Without an Email

Forgetting your password can be tiresome, especially if you’re the (only) administrator. Owncloud allows you to reset your password via the user-supplied email address, but this does of course only work if you have an email associated with your account.

Furthermore, the system needs to have a mail server configured. Perhaps you don’t, because of some reason, want to have a mail server up and running.

So here’s how you reset your owncloud admin (or user) password the quick and dirty way.

NOTE: This worked for me, at the time of posting. Future versions might not work this way. Please do proper research before looking into my solution. I am in no way responsible for you breaking something. OK?

First, log in as root or make sure you have sudo access. Or at least make sure you are allowed to modify the owncloud files.

cd /var/www/owncloud/core/lostpassword

We will be modifying the password reset function, instead of going into the database. Please back your existing controller.php file up, and understand that you are going to be susceptible to hacking attempts while making the following modifications.

nano controller.php

We want to supply an email to the system by hard-coding it, and then print the password-reset URL to us. OwnCloud will then continue with its own procedures and attempt to mail the password to the email you provide. Essentially we’re printing the link you’re supposed to get via mail. If you leave this modification in place, anyone will be able to gain access to your OwnCloud!

Go to line 48 and on the line below insert (line 48 begins with $email)

$email = “your-email@domain.tld”; //Set email

Then go to line 53 and on the line below insert (line 53 begins with $link, and this is line 53 after you added the previous line.)

echo $link; //Print email reset link (DO NOT LEAVE THIS IN PLACE)

Now go to your OwnCloud, and try to log in. When it fails, click forgot password link, and then enter your username. You should see the password reset URL pop up. Copy, paste, and chose a new password.

Then, enter

nano controller.php

And remove the lines you just added! DO NOT LEAVE THEM IN PLACE.

I found this to be easier than to edit the database.

Cheers!

Join the Conversation

20 Comments

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. Sorry, correction: the active Owncloud installation with the problem is still at Owncloud 5.0.10.! But still your solution doesn’t work.

    My test Owncloud installation is Owncloud 8.

    Looks like the best way to reset a password but isn’t working for me.
    Get only a blank page. So, isn’t working for Owncloud 5.

    My problem:
    # An intern at my job has changed and forgotten the admin password.
    I don’t know why, but this is really bad.
    # Password recovery by username and email gives this error:
    “A problem occurs during sending the e-mail please contact your administrator.”
    # Tried a lot of solutions found on the internet but non of them work for Owncloud 5.

    What i still have and can do:
    # Login with the other (not admin) accounts.
    # All administrator rights on the server. I am the responsible one.

    Do you know how to get your above solution working for Owncloud 5?

    I know that the php files are in the folder “lostpassword” and in “lostpassword/templates/”

    Thanks for any help.

  2. Hello

    Looks like the best way to reset a password but isn’t working for me.
    Get only a blank page. So, isn’t working for Owncloud 8.

    My problem:
    # An intern at my job has changed and forgotten the admin password.
    I don’t know why, but this is really bad.
    # Password recovery by username and email gives this error:
    “A problem occurs during sending the e-mail please contact your administrator.”
    # Tried a lot of solutions found on the internet but non of them work for Owncloud 8.

    What i still have and can do:
    # Login with the other (not admin) accounts.
    # All administrator rights on the server. I am the responsible one.

    Do you know how to get your above solution working for Owncloud 8?

    I know that the php files are now in the folder “lostpassword” and in “lostpassword/templates/”

    Thanks for any help.

  3. After various retries to recover passwords, I have found the easiest (for me) way to do it – simply copy old owncloud.db file (owncloud/data/owncloud.db) over the new and restart owncloud via browser. It will again start updating of files and – voila – everything works fine – all passwords and users are here, all shares, and I hope everything else also!

  4. Thank you so much! This worked a treat even on my Digital Ocean droplet installation where I had to fiddle about with the Nano editor. Finally have my OwnCloud back.
    Thank you again. Where is your donation button?

  5. Hello,

    For my version (7.01), the file is /var/www/owncloud/core/lostpassword/controller/lostcontroller.php
    I do the modification

    $email = $this->config->getUserValue($user, ‘settings’, ’email’);
    $email = “your-email@domain.tld”; //Set email
    if (empty($email)) {
    throw new \Exception(
    $this->l10n->t(‘Couldn\’t send reset email because there is no ‘.
    ’email address for this username. Please ‘ .
    ‘contact your administrator.’)
    );
    }

    $link = $this->getLink(‘core.lost.resetform’, $user, $token);
    echo $link; //Print email reset link (DO NOT LEAVE THIS IN PLACE)
    $tmpl = new \OC_Template(‘core/lostpassword’, ’email’);
    $tmpl->assign(‘link’, $link, false);
    $msg = $tmpl->fetchPage();

    Then, i click forgot password link, but nothing happen :(
    Could you tell me where i’m wrong ?

  6. Thank you that helped me!!
    Maybe you should add the owncloud version 6.x to the Heading.

  7. Dear Friends
    I Forget the email and password of that cloud which i created for my usderstanding in centos 6 ,I cerated 2 users on that server. The names of that users i found in /var/www/html/owncloud/data/ directory where i found .db file can I recover the password from updating that file??? .. After giving following commands it show me the users I created with their password which in encrypted format . plase help me ….
    sqlite3 kim.db
    select * from oc_users;

  8. Hmmm – followed the steps, but when I try to reset the password I get:

    Parse error: syntax error, unexpected ‘@’ in /home/fourLegsGood1/threesquirrels.com/owncloud/core/lostpassword/controller.php on line 49

  9. Thanks!

    I had to go to the file /var/www/owncloud/core/lostpassword/index.php and add your lines to line number 18 and 21. I probably have a different version of OwnCloud, but it worked at first try.

    Takk skal du ha.

  10. So funny that two guys needed this on the same day. Thanks for publishing it!

    Now I just need to figure out the OC upgrade process…

  11. Thanks a lot for this post! So simple and effective.

    I almost lost hope when I realized that hard-coding my email address into the controller.php code couldn’t work due to the missing mail configuration.

    Your my coding hero of the day :)