Reset of admin password

Reset of admin password

by David Paige -
Number of replies: 9

I administer a Moodle 2.5 system that I didn't set up, so I have inherited some of the decisions of the creator.  It was created on an Ubuntu Precise Pangolin host.  I have ssh access to the ubuntu host, and I have the root password for the Moodle database.  This is virtualized on an ESXi host.

I changed my manager password recently, and may not have written it down correctly.  Now I can't log in to my manager account.  How do I use the mysql command line to change the manager password?

The first step would probably be to take a snapshot in case I damage something, and then I can roll back.


Thanks.

Average of ratings: -
In reply to David Paige

Re: Reset of admin password

by Just H -

Why not use the inbuilt forgotten password functionality?

In reply to Just H

Re: Reset of admin password

by David Paige -
I need to look more closely, but I think the inbuilt forgotten password functionality requires an email account.  We chose not to create an email server since we are doing the training locally rather than over distance learning.  Is there a way to use the inbuilt functionality other than to the registered email account?  I'll have to pull out my Moodle 2 book and read through that portion.  I hope I don't need to resort to root modification of the mysql database.

I wonder if this might work as well, to make one of the existing accounts an administrator.

https://moodle.org/mod/forum/discuss.php?d=18034#p85534

Thanks.
In reply to David Paige

Re: Reset of admin password

by David Paige -

I've been poking around the Moodle site, and reading Using Moodle 2e.pdf.  I came across this link, which may solve my problem.  Will it work if I perform it?  It should lower my blood pressure a bit if it will work.  I guess I can test it on a regular user first.


(https://docs.moodle.org/22/en/Administration_via_command_line)

Reset user password

If you happen to forget your admin password (or you want to set a password for any other user of your Moodle system), you can use reset_password.php script. The script sets the correctly salted password for the given user.

   $ sudo -u apache /usr/bin/php admin/cli/reset_password.php

Average of ratings: Useful (2)
In reply to David Paige

Re: Reset of admin password

by Ken Task -
Picture of Particularly helpful Moodlers

There is yet another way ...

In config.php file enter a line to grant user ID's site admin roles.

$CFG->siteadmins="2,#";

where 2,# are known user ID's.  User ID 1 is guest (don't use that one here), User ID 2 is normally the original user created when the Moodle was first installed.   Admin level users may have added many moons after install so those users will not be sequential but spread out.   In your case, your user ID might be something like 4420, as an example.

So, using any account where you can login as that user, login and look at the user ID which will display in the URL line to some resources in Moodle (like Profile).

So Bob Jones - bjones - is a known account and can authenticate (login) to Moodle.  ID is 354.

In the config line above replace # with 354.  Save the config file.   Login as bjones.

Go to the admin user - the one you desire to use as the admin - edit profile, change password.   Don't worry about getting notification.   Write it down. ;)

Logout from bjones.

Try the admin account again.

If successfull, re-edit your config.php file and comment out the siteadmins line you added by placing // in front of it.  No need to reboot/restart anything.   While there, might add that other user account to the siteadmin config line.

bjones is no longer site admin level and you should be able to now login with the admin account.

HINT: create another account using info you know.  Set that user as admin level.   Use it only as a 'backup' to accessing the Moodle as admin level in case of other hickups.   This is not the normal process so any future admins should be added via the normal Moodle UI as an admin level user.

'spirit of sharing', Ken

Average of ratings: Useful (6)
In reply to Ken Task

Re: Reset of admin password

by David Paige -

Thanks.  I'll give that a try.  This was the one system which had slipped through the cracks, and didn't have a backup administrator account. 

In reply to Ken Task

Re: Reset of admin password

by David Paige -

Ken,

Modifying the config.php file worked perfectly.  I was able to reset my admin account password without any issues.  I do have a backup account on this server, in case this happens again.


David

In reply to David Paige

Re: Reset of admin password

by Ranil Peiris -

Hi

You can use a simple method if you know at least one password. Go to phpmyadmin. Run this query "select * from mood_user " .  Go to result table and copy the entire cell that contain the known password (it is hashed). Then paste in admin's password cell. Then, you can login with admin user with the copied password. 

Ranil

Average of ratings: Useful (1)