1

forgot the moodle admin password of my local moodleyour text server i am using the version 4.1 moodle i know the username but unfortunetly forgot the password my local moodle server. i have tried to forgot the password i havent give the smtp address so i cant recieve the mail of reset password

enter image description here

login to moodle server but i have forgot the passwqord so i am not able to login

3 Answers3

2

You can reset the password from the command line

php admin/cli/reset_password.php --username=admin --password=newpassword
Russell England
  • 9,436
  • 1
  • 27
  • 41
  • Its not working i have tried but not worked – Noorain Ansari Jan 09 '23 at 07:37
  • Try without the parameters, it will prompt you for the name and password `php admin/cli/reset_password.php` - if it still doesn't work, then double check `config.php` to make sure you are using the correct url and database. – Russell England Jan 09 '23 at 10:05
0

Here is a more hacky approach that works provided you have access to the database.

For context, Moodle uses the PHP function password_hash() to generate a password hash for users. The basic idea is that you want to use this function in a plain PHP file outside of Moodle to output a password hash of a new password. This hash is then manually saved in the password field in your mdl_user table using your database client and your new password used to login to the site.

PHP File:

<?php
echo password_hash("new_password", PASSWORD_DEFAULT);

Example output of password_hash:

$2y$10$NCC4PVZ1kTRg4bT21yEl2eUVWMf3lkbYtczTn8vB53qNwTqtN9jwS

KSankar
  • 559
  • 4
  • 10
0

It happens to the best of us, me included, what I did was the following:

  1. Access Moodle's DB
  2. Locate the user table
  3. Go to the "username" column
  4. Find the "admin" user
  5. Use php's password_hash function
  6. Update the password in your DB
  7. Most importantly save your changes

Now you should be able to access your local Moodle installation using the new password.

Always keep records of your passwords to avoid tiresome issues like this one.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
haris.doku
  • 36
  • 4