Reset Moodle admin account via shell

In order to quickly reset Moodle’s admin password (or any other user account for that matter) you can issue the following command via the shell:

/opt/lampp/bin/mysql -h 127.0.0.1 -u root --password=rootpass --database=moodle -e "update user set password='`/opt/lampp/bin/php -r "echo md5('something_fancy');"`' where username='admin'"

Note that the command above uses a XAMPP setup. You should replace the path to the MySQL/PHP executables accordingly.

Conclusion: Since Moodle’s password system currently only uses plain MD5 to save passwords (without salting it…) it is rather easy to change existing passwords via the shell or any other script.

Update: MoodleDocs provides documentation on how to use the reset_password.php script, see http://docs.moodle.org/en/Administration_via_command_line#Reset_user_password.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *