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 -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

Leave a Reply

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

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