Manually change the moodle admin password with acces to phpMyAdmin or create another admin account?
Asked Answered
I

9

8

The password for an admin login in a moodle platform is lost.

I have access to the phpMyAdmin.

I went to the mdl_user table and there I can see or edit this table.

How should I proceed? Can I change the admin encripted password and secret key to a known password or is it simpler to just add an admin user?

How would that be?

Intramolecular answered 5/5, 2012 at 20:18 Comment(1)
You could just check the sourcecode and see how the hash is calculated. You could then make a new hash with your new password with their hashing-function.Fallal
I
0

Apparently Moodle version 1.9.9 only hashes the passwords with md5 once (with no salt at all!!).

So the only thing to do is to replace the in the admin row the password filed with whatever password you want with a md5 applied.

Intramolecular answered 5/5, 2012 at 22:19 Comment(1)
How are you so sure about moodle version being used here?Shoreline
H
15

only tested on Moodle 2

You can reset any user password from command line. In your Moodle root:

php admin/cli/reset_password.php

For dev prod environment you may also want to disable the password policy check (so you can enter a small and quick to type password). Edit reset_password.php and comment:

// if (!check_password_policy($password, $errmsg)) {
// cli_error($errmsg);

// }

Helmand answered 29/4, 2015 at 9:50 Comment(2)
Confirming this works for 2.9.1. Seems to me this should be the correct, chosen answer. No fuss, no muss.Total
Excellent and simple answer. Works on Moodle 3.0.Littles
P
14

Open up Moodle's config.php file, find the line where $CFG->passwordsaltmain is defined, and copy it's value (it's a long string of random characters).

In PHPMyAdmin, run the following query, substituting values as appropriate:

UPDATE mdl_user SET password = MD5(CONCAT('<new password>', '<password salt copied from config>')) WHERE id = <id of admin user>
Planetoid answered 10/5, 2012 at 9:4 Comment(1)
My config.php didn't have the $CFG->passwordsaltmain value, however the following without the salt worked - UPDATE mdl_user SET password = MD5('<new password>') WHERE id = <id of admin user>Wilks
G
5

ANOTHER, MORE QUICK AND EASY WAY TO GENERATE A NEW MD5 HASH PASSWORD:

  1. Go to http://www.miraclesalad.com/webtools/md5.php and create a new password like... wintersnow123~ (it will look like this: "003df036e1a99aad3eaba7c3ca46723d" without quotes).
  2. Copy the md5 hash password generated from the word you submitted (it's easy) and be prepared to paste it.
  3. Using phpMyAdmin, log into your MySQL database.
  4. Navigate to the user table (for Moodle, it's called "mdl_user") and browse the data.
  5. When you find the "admin" user account, click on edit, and paste in the new password you copied in Step 2 ("003df036e1a99aad3eaba7c3ca46723d"). (Into the password field.) This will replace what you had previously.
  6. Try logging in with your admin user account and the new password (Password: wintersnow123~)
Gerger answered 21/9, 2016 at 18:56 Comment(0)
F
1

You could just check the sourcecode and see how the hash is calculated. You could then make a new hash with your new password with their hashing-function.

I checked the source-code and depending on the configuration, its hashed with md5 or sha1. So check your config and make a hash of your own.

// From the sourcecode:
if ($this->config->passtype === 'md5') {   // Re-format password accordingly
      $extpassword = md5($extpassword);
} else if ($this->config->passtype === 'sha1') {
      $extpassword = sha1($extpassword);
}
Fallal answered 7/5, 2012 at 23:1 Comment(0)
H
1

HOW TO CHANGE THE PASSWORD USING MD5 HASH:

  1. Log into phpMyAdmin. cPanel hosting will have a database utility called PhpMyAdmin within the cpanel. If the Moodle is installed on a non cPanel hosting, contact the hosting company for information on how to edit your database on the server. For more information on logging into PhpMyAdmin, please see the article on "How do I manage a MySQL database in PHPMyAdmin in my control panel (cpanel)?".

  2. In PhpMyAdmin, find the table called mdl_user and select it. Since Moodle has many tables, the mdl_user table may be on the second page. Select the second page. Click the mdl_user table.

  3. After selecting the table, find the table row for the user that is being edited. Click the Edit link with the pencil icon.

  4. There will be a series of characters and numbers in the password field. This is an encrypted password so it cannot be viewed in the database. Replace the encrypted text with the new password for the login.

  5. Next, in the drop down menu to the left, select MD5 then click Go.

This can also be done for the Email address and the Username. The Email and the Username do not need the MD5 hash.

Hooks answered 23/7, 2013 at 7:37 Comment(0)
I
0

Apparently Moodle version 1.9.9 only hashes the passwords with md5 once (with no salt at all!!).

So the only thing to do is to replace the in the admin row the password filed with whatever password you want with a md5 applied.

Intramolecular answered 5/5, 2012 at 22:19 Comment(1)
How are you so sure about moodle version being used here?Shoreline
L
0

Currently Moodle introduces a salt in passwords to uniquely encrypt passwords in each installation.

If you didn't delete or changed guest account password you can copy its value to admin user password to be able to login.

Later you can change it to whatever you like.

User accounts are stored mdl_user table.

Lagas answered 7/5, 2012 at 22:47 Comment(0)
T
0

For Moodle 3.10.

Step 1 Create a temp PHP file in Moodle root directory to generate the password.

<?php
include('config.php');
echo password_hash('new_password', PASSWORD_BCRYPT);

Now run this php script to get the new password generated by the Moodle framework.

Step 2: Open PHPMyAdmin and select the Moodle database. Run this query.

update mdl_user set password="new_password_hash" where username="admin";

Step 3: Delete the temp php script file from the Moodle root directory.

Tannenbaum answered 26/6, 2021 at 12:1 Comment(0)
M
0

As of 2024, on moodle 4.1.9 we can use 'ignore-password-policy' parameter:

sudo -u apache /usr/bin/php admin/cli/reset_password.php --username=admin --password=cheesyPassword --ignore-password-policy

By the way, i use apache user, you might use www-data, depending on your operating system.

Tx, bye.

Mccowyn answered 13/3 at 11:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.