change admin's password

change admin's password

by Alex Saevich -
Number of replies: 94
Hi, everybody.
I've forgotten admin's password in my moodle instance. I have some experience in database adminestration, so i've found method to change admin's password rihgt in my MySql database (called moodle).
And when I connect to this db...like this,

admin -

I use new password and connection is successfull

but moodle doesn't see new password

what's wrong?

Sorry for my English.
Average of ratings: -
In reply to Alex Saevich

Re: change admin's password

by Shane Elliott -
Picture of Core developers Picture of Plugin developers
You have changed the password to access the database. Moodle user's (including the moodle admin) details are stored within the database.

If you need to reset your password, just click on the 'Send my details via email' button on the login page. Then enter your email address and an email will be sent to you with instructions for resetting the password.
Average of ratings: Useful (1)
In reply to Shane Elliott

Re: change admin's password

by Alex Saevich -
Thaks for feedback.

Some details. My moodle is newbie and all are in localhost.
I haven't any valid smtp parameters in my moodle. So, I cannot send any mail from moodle.

What can I do in this situation?
In reply to Alex Saevich

Re: change admin's password

by Shane Elliott -
Picture of Core developers Picture of Plugin developers
Two options for which you will need to access the database directly. (phpMyAdmin is great for doing all this rather than using command line mysql)

1. In the user table set the email field of the admin account to a localhost address eg root@localhost and then request a password reset for that address
Moodle will only use the SMTP settings if you have already set them. Otherwise it will use the internal PHP mail function. This should work fine for a local address.

2. Can you log in or set up a general user account? If so then have a look here:
http://moodle.org/mod/forum/discuss.php?d=18034

And if the above fail, try the attached script. Put it in the root moodle folder (the same location as config.php) Edit the username and password to suit. Then call it directly from your browser eg http://localhost/moodle/passchange.php
You may want to delete it afterwards as it is a security risk.
Average of ratings: Useful (10)
In reply to Shane Elliott

Re: change admin's password

by Alex Saevich -
You are the great! cool
Thanx for the very useful answer.

I've used your script. I think it's the shortest way to solve same problem.

And the last question (I hope it will be last smile )
However, where moodle does keep the admin's password?




In reply to Alex Saevich

Re: change admin's password

by Shane Elliott -
Picture of Core developers Picture of Plugin developers
Passwords for all users (including admin) are stored (encrypted) in the 'user' table.
Admins are just normal users with an additional entry in the 'user_admin' table.
Average of ratings: Useful (1)
In reply to Shane Elliott

Re: change admin's password

by Ahmed Metwally -

Elliott, you really are a great guy. Such a scribt was very useful for me. It helped me a lot. I guess all moodle admins shoud visit this topic.

Thanks a lot,

In reply to Ahmed Metwally

Re: change admin's password

by Karen Erickson -

I am trying to get into 1.7 to move the info to our new moodle. 1.9.2 .... but don't have my passcode as admin.

my moodle is on the server within a website

slipcovernetwork.com/sse-classes so when I go into config php I don't find my admin password, I find the site password.

Suggestions anyone.

Karen

slipcovernetwork@gmail.com

In reply to Shane Elliott

Re: change admin's password

by Dennis Flynn -
Shane Elliot's response about the password being stored encrypted is the key. If you change the password, you have to use an md5 hash. I'm sure it's easy enough at the command line, but in phpMyAdmin you just open the record for the user, type in the new password in the password field, and choose the md5 option in the drop-down box.
Average of ratings: Useful (2)
In reply to Dennis Flynn

Re: change admin's password

by Seiti Yamashiro -
Or just insert

d41d8cd98f00b204e9800998ecf8427e


as a password. Because
MD5("") = d41d8cd98f00b204e9800998ecf8427e, so now your passoword is a empty string.
Average of ratings: Useful (9)
In reply to Seiti Yamashiro

Re: change admin's password

by luiz rosalba -
so moodle uses md5 ... thats an important thing to know...
In reply to Seiti Yamashiro

Re: change admin's password

by Pablo Española -
Thank you, Seiti Yamashiro! Your idea works very well! I was able to access my site after I lost access as a result of an upgrade. Great idea! Pablo
In reply to Seiti Yamashiro

Re: change admin's password

by J Guzman -

Thanks Seiti, this solution worked great.

In reply to Dennis Flynn

Re: change admin's password

by Chris Baldwin -

This one worked for me - 7 years after the original post - using M2.6 - on localhost after an upgrade:

"Shane Elliot's response about the password being stored encrypted is the key. If you change the password, you have to use an md5 hash. I'm sure it's easy enough at the command line, but in phpMyAdmin you just open the record for the user, type in the new password in the password field, and choose the md5 option in the drop-down box."

Dennis Flynn - 2007.

Average of ratings: Useful (1)
In reply to Chris Baldwin

Re: change admin's password

by Luis de Vasconcelos -

An easier way is to use phpMyAdmin to copy the password hash from a profile that you do know the password for and update the profile whose password you need to change with that known password hash. e.g.:

SELECT password FROM mdl_user WHERE id = <the id of a moodle profile that you DO know the password for>;

UPDATE mdl_user SET password = <the password from above> WHERE id = <the id of the profile whose password you have forgotten>;

Then login to the profile with that password and change the password to something you won't forget...

I might be wrong, but I I don't think the password algorithm is a straight MD5 hash. I think it's a bit more complicated than that.

In reply to Luis de Vasconcelos

Re: change admin's password

by Guillermo Madero -

Hi Luis,

It's MD5 in older versions, since 2.5 it's a stronger algorithm.

In reply to Shane Elliott

Re: change admin's password

by Michael J. Ryan -

Hi Shane,

I have no 'User_Admin' table.  When installing Moodle during the database creation process I received no error messages.  So, why is this table missing and what can be done about it?

Also, maybe you can answer this for me.  I've seen references to 'Admin -->Configuration.  I assume that 'Configuration' is an option on the Administration menu.  But when I login (I'm the administrator), the Administration menu has no such option either at the top level or within any of the other options.  Am I looking in the wrong place or is it missing?  What do I do in either case?  (I'm using Moodle 1.8)  Thanks.

Mike Ryan

In reply to Shane Elliott

Re: change admin's password

by harvey hall -

For some reason when I look into the table with all the users, there is no admin no matter which way I sort them. Any suggestions?

Thanks

Harvey

In reply to Shane Elliott

Re: change admin's password

by John Spradlin -

Once I got into the database, i just changed the email associated with the admin account and then used the forgot password option.

In reply to Shane Elliott

Re: change admin's password

by Erik Ringmar -
Hi Shane,

You are an awesome guy. People like you restore my faith in humanity. You've just saved me from a major headache.

yours,

Lin
Average of ratings: Useful (1)
In reply to Erik Ringmar

I need step by step on chaning admin pswd in MySql

by Elya Nilas -
Please help as I have tried sending a reminder of pswd e-mail, but the login will just NOT accept it for some reason. Seems like i have to go the MySQL side an dchange it there. Can somebody tell me step by step on where in MySQL I have to go and specifically in the table of MDL_USER? If yes, then what do I do and which filed I go to and what do I look for in there and what do I chagne. Please advise. I do apologize but with today's world of 25,000 pswds I just..lapsed out.
In reply to Elya Nilas

Re: I need step by step on chaning admin pswd in MySql

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
In reply to Anthony Borrow

Re: I need step by step on chaning admin pswd in MySql

by Elya Nilas -
No. I have tried to change the pswd via MySql by going to mdl_user table and browsing for the field Password. I have then changed it to "whatever I typed" and selected MD5 from drop down list. I have since tried to log on to the course but it WON'T allow me in. Period. Any suggestions?
In reply to Elya Nilas

Re: I need step by step on chaning admin pswd in MySql

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
I am glad that we were able to get you working again by using phpMyAdmin to change the record in mdl_config where name=dbsesssions from 0 to 1. This allows for the sessions to be handled by the database rather than stored on the filesystem. I suspect that your problem is a permissions issue which I hope you will be able to resolve with your host. If not, at least you can have your site up and running even if it costs you a few more queries and database activity. Happy Moodling.
In reply to Shane Elliott

Re: change admin's password

by William Oakes -
Thank you, Shane! It is now 2008 and your script still works wonders!

However, I had to run "localhost/passchange.php" and not "localhost/moodle/passchange.php" in order for the browser to find the file. Probably just my setup but I thought I would post a word about it for posterity.

Again, THANKS!

Bill
Average of ratings: Useful (1)
In reply to William Oakes

Re: change admin's password

by Richard Enison -
WO,

That's exactly what it is. Some Moodle sites are set up so that the main Moodle directory (where index.php, install.php, config.php, config-dist.php, etc. are), usually called moodle, is the web document root (aka home directory), so that Moodle is accessed as localhost or yourmoodledomain.com, etc. Others have moodle as a subdirectory of the root, so they have to use localhost/moodle or yourmoodledomain.com/moodle. It's a matter of how the webserver s/w (Apache, IIS, etc.) is configured, although I think it is also possible to change it by messing with the DNS records.

RLE
In reply to Richard Enison

Re: change admin's password

by Scott van Niekerk -

Any suggestions for if I can no longer login to my moodle on my server?

Is there a standard admin username and xxx password? Or which of my files would I look in to detect that info?

Thanks

In reply to Scott van Niekerk

Re: change admin's password

by Richard Enison -
SvN,

Read the rest of this thread. That's what it's all about! I can tell you where it's stored (it's in the database, unless you're using a non-standard authentication method), but it's encrypted, so you can't "detect" it. But you can change it to whatever you want it to be. You have your choice of methods for doing that in this thread, including a script that will do it for you automatically.

RLE
In reply to Richard Enison

Re: change admin's password

by Nitaq Telecom -

Hi All,

I don't have mdl_user_admin table and I cant retrieve my admin password, can anyone help?

Thanks.

Ahmed

In reply to Nitaq Telecom

Re: change admin's password

by Richard Enison -
NT,

Read RK's post of January 14, 2008 responding to MJR's question, which was the same as yours. The name of the table has changed. Then read the rest of this thread.

For a short-cut, click the word "post" above.

RLE
In reply to Shane Elliott

Re: change admin's password

by Ashish Srivastava -
Hello Sir..
After Running the Script,
http://acel.limewebs.com/passchange.php
It shows Password Changed, Still I cant access with admin login
Its Showing Error as ::

"A server error that affects your login session was detected. Please login again or restart your browser."

Please Respond..
Thanks in Advance
In reply to Shane Elliott

Re: change admin's password

by Tokhir Akhmedjanov -

Hi Shane Elliott

Thanks for your advise on changing admin password.

I consider it usefull.

Wish you all the best

with respect,

Tokhir, moodler, translator of Uzbek Language package

In reply to Shane Elliott

Re: change admin's password

by James Gray -
Just a quick note to say phew!! thank you for the passchange script
I set-up Moodle a while ago and forgot the admin password
In reply to Shane Elliott

Re: change admin's password

by en hockers -
After migrating to a new server, login problems for admin user were fixed with this script. Also, becuase the guest login also got corrupted this script was helpful to change the guest password to 'guest'. This reenabled guest login without need for password.
In reply to Shane Elliott

Re: change admin's password

by Larry Neuton -

After I upgraded to the latest version of Moodle at http://librarylearningcenter.com I cannot log in as administrator.    The new password that moodle sent to my email address doesn't work either.  

 I just tried using the passchange.php script but when I go to http://moodlesite/passchange.php I get a blank white screen with the words "Invalid Username".  

I can get to PHPMyAdmin but I don't really know what I'm looking for there (and I don't want to mess anything up).

Any suggestions?

In reply to Shane Elliott

Re: change admin's password

by Dick Taytor -
Your passchange.php script is a really useful tool - and a lifesaver! Thanks Shane!

Unfortunately, it looks like it won't work in Moodle 2.0 - didn't for me. Good thing it was only a test server on localhost.
In reply to Dick Taytor

Re: change admin's password

by Christy Burcham -

Just used this script today and it saved me a ton of time!! Worked in 1.9.1 for me.

Thanks for sharing!!

In reply to Shane Elliott

Re: change admin's password

by tandin dorji -

hi shane!

I went through your post and found that passchange.php could change my forgotten admin password.I followed your steps, but i still couldnt get into my admin page.

In my case, I hosted my moodle in different server and now i wanted to set iit up in a new server which runs CentOS 5.0.

I did the backups for moodle server and installed into the new server, and for the safty sake i wanted to test it first on localhost. I did install successfully, but i couldnt login to admin. not even into single user account that was there in pervious server.

i used your passchange.php script, it gives the msg that password is changes but i still cannot get into the admin.

i even tried using phpmyadmin, but still couldnt get it done.

BTW, my old server was also running on CentOS 5.0

 

Thanks you.

In reply to tandin dorji

Re: change admin's password

by Emanuel Delgado -

Hi,

If you have access to phpmyadmin, just copy guest user password to admin (table mdl_user).

If you didn't change it, it is "guest".

Then enter as admin and change it inside Moodle.

ed

In reply to Shane Elliott

Re: change admin's password

by Raman Joshi -

Hello Shane,

I have the same problem - have lost my admin password and do not have an email setup. Tried following passchange.php, but just get a blank page:

<?php
include('config.php');
////////////////////////////////////////////////////////////////////

$username = 'raman';
$newpassword = 'P4$$w0rd';

////////////////////////////////////////////////////////////////////

global $DB;
if ($userobj = $DB->get_record_select('user', "username='$username'", array('id' => $password))) {
$userobj->password = md5($newpassword);
$DB->update_record('user', $userobj);
echo 'Password changed';
} else {
echo 'Invalid username';
}
?>
 
PLEASE HELP...
Thanks,  Raman
In reply to Raman Joshi

Re: change admin's password

by Glenys Hanson -

Hi Raman,

Have you seen this discusssion? http://moodle.org/mod/forum/discuss.php?d=18103

These seem to be the solutions that to work best:

In phpMyAdmin

In the table mdl_user

Insert:
d41d8cd98f00b204e9800998ecf8427e

as a password. Because MD5("") = d41d8cd98f00b204e9800998ecf8427e, so now your password is a empty string. Then login with nothing in the password field.

Thanks to Seiti Yamashiro - Tuesday, 20 March 2007, 11:08 PM

****

If all else fails and you can access the database via phpMyAdmin, go to the mdl_user table and copy the guest password into the Admin password field. It is encrypted, but the default password for Guest is "guest". You can then log in and change the password. That should get you out of trouble.

Colin Fraser - Friday, 11 February 2011, 07:27 AM

****

This is what worked for me :

In phpMyAdmin

Click on the moodle database on the left.

In the new window, in the list on the left, find the table mdl_user (it may be on a following page)

Select the file to edit with the "pen" icon.

Change the username to whatever you want but not "admin" (on an online site because of security risk)

Change the password to: guest

Click on the "Go" button at the bottom of the screen.

Log in to your Moodle site with the password "guest"

Change the password in your profile to a very strong one.

Cheers,

Glenys

In reply to Glenys Hanson

Re: change admin's password

by Raman Joshi -

Thanks Glenys.

I don't know what the problem is - I did use phpMyAdmin and changed the password as you suggested. I could also see that running Shane's script does reset the password in the database.

However, when I try to log in, it does not accept the password. Is there anything in config.php which influences this?  I remember reading something about password salting...

Best Regards,

Raman

In reply to Raman Joshi

Re: change admin's password

by Guillermo Madero -
In reply to Guillermo Madero

Re: change admin's password

by Glenys Hanson -

Hi Raman,

I just had to do this yesterday and found I had to something slightly different from my instructions above:

In phpMyAdmin

  • Click on the moodle database on the left.
  • In the new window, in the list on the left, find the table mdl_user (it may be on a following page)
  • Select the file to edit with the "pen" icon.
  • Change the username to whatever you want but not "admin" (on an online site because of security risk)
  • Copy the "guest" password.
  • Replace the "admin" password by the "guest" password
  • Click on the "Go" button at the bottom of the screen.
  • Log in to your Moodle site using the word "guest" (without the quotes) as the password.
  • Change the password in your profile to a very strong one.

I think Guillermo is saying the same thing in different words.

It's very difficult to be clear, isn't it? Maybe the screenshot below of phpMyAdmin will help. There I copied "a7b811037c0c9a6c697660cb28fc4b57", and then opened admin for editing and replaced "3fd111aef85ef819c22d89fa1f90b448" by "a7b811037c0c9a6c697660cb28fc4b57"

Cheers,

Glenys

Attachment 2011-09-15_01-02-07.png
In reply to Glenys Hanson

Re: change admin's password

by Guillermo Madero -

¿My instructions weren't clear?

Anyway, eventhough the idea is similar, it is not exactly the same. While the "the guest password paste" solution is a shorter solution, there are some instances where it might not actually work.

Cheers!

In reply to Shane Elliott

Re: change admin's password

by William Aufman -

Thank you you have saved my moodle.  I never remember password so I always let my secured browser remember it for me.  You sent me down the right path an it worked.  Sorry for anyone that didn't have it as easy as me.  THANK YOU!!big grin

In reply to Shane Elliott

Re: change admin's password

by viovel ros -

Hello Shane Elliott

I'm so sorry!... I have uses scripts in "moodle/admin/cli/reset_password.php" but I can't change admin's password! sad

Can you show me some detail steps?

Thank you so much!

In reply to Shane Elliott

Re: change admin's password

by Abhimanu Sharma -

script passchange.php doesn't works for me.
and also i don't have any other accounts in my moodle localhost installation. so please tell me how to access phpmyadmin without login into any other account.

If there is any other way to login to admin account other than these two options? please let me know!!

In reply to Abhimanu Sharma

Re: change admin's password

by Guillermo Madero -

Hi Abhimanu,

What two options did you try, passchange.php and... ?

phpMyAdmin is a MySQL DB manager. Do you have installed?

In reply to Shane Elliott

Re: change admin's password

by Pavel Krejci -

Easiest solution would be to edit Moodle library file lib/moodlelib.php in plain-text editor. Backup the original file before editing.

find the line which reads:

function validate_internal_user_password($user, $password) {

add the following 1 line below it:

return true;

save it and voila - any password goes. Revert the change after you reset your Moodle password ASAP to keep the site secure.

Attachment disable-password-check.png
Average of ratings: Useful (1)
In reply to Alex Saevich

Re: change admin's password

by Shane Elliott -
Picture of Core developers Picture of Plugin developers
It's been a while since I've read this discussion topic. My apologies to those who asked questions that I never responded to.

Someone contacted me recently to say thanks for the script (thanks Paul W for contacting me), which prompted me to post an updated version of this script that we find ourselves using much too often. It does a few other things as well!

I've added it as a miscellaneous entry in the Modules and Plugins database:
http://moodle.org/mod/data/view.php?d=13&rid=2529

Cheers,
Shane.
Average of ratings: Useful (1)
In reply to Alex Saevich

Re: change admin's password

by dave simons -
Whoa,,,that worked awsome,,,thanks
In reply to dave simons

Re: change admin's password

by Carlos Silva -
Just straed with Moodle, actually completed the install now went back months later to continue and can't log in. Fortunately I have ftp access.

This script looks exactly like what I need;

But here is my firts problem,
is the "administrator" account, admin, Admin, administrator or Administrator?

Looking in my moodledata/user/ I have a /0 (empty) and under that /2 (also empty) so I have no idea what my admin. Admin, administrator or Administrator account is.

Any help would be greatly appreciated.

Thank you in advance.
In reply to Carlos Silva

Re: change admin's password

by mo ollek -
It is usually admin - when you installed installed it, you would have set up the password at that point.
In reply to mo ollek

Re: change admin's password

by Carlos Silva -
Thank you mo ollek.

Tried logging in to admin with what I thought the password (and several variants) with no luck , so I am going to try the script.

Again thanks for the quick response.

In reply to Carlos Silva

Re: change admin's password

by Carlos Silva -
WOW the script worked like a charm. It is also now deleted from my root folder it works so well.
I am also going to need to study up on hosting security !!!!!!!

Again thank you.

In reply to Carlos Silva

Re: change admin's password

by Daniel Berman -
Just upgraded to the latest version of Moodle, went through the UTF upgrade component but I can't login. I have tried changing the admin password in the database and/or changing it to the MD5 hash of "" and no result. I can't even get it to trigger a password reset email. Tried the above script and got an invalid username message. Any ideas?

The url is sitting at http://christianfamilyplanning.net/courses yes it was a fantisco install which was migrated to softaculous.
In reply to Daniel Berman

Re: change admin's password

by Keith Still -
I've the same problem - installed latest version, can't login and it doesn't seem to email me the password reset. Any idea how to get back into the system?
In reply to Keith Still

Re: change admin's password

by Martin Lewis -
Try copying over the last working config.php. The current one may have a different 'salt' code. (rename the original first eg config.bkp)

I did the same thing once, new version wouldn't let me in. Copied over the old salt code, worked fine.

Good Luck.
In reply to Keith Still

Re: change admin's password

by Fernando Oliveira -
Picture of Plugin developers
Check your moodledata folder and make sure all permissions are 777. This worked for me.
In reply to Keith Still

Re: change admin's password

by Karen Erickson -

I am having the same problem - installed latest version, can't login and it doesn't seem to email me the password reset. Any idea how to get back into the system?

Help, help...

Is anyone out there that can help?

In reply to Karen Erickson

Re: change admin's password

by Sary Huang -

Hi, Karen

Here's how I get around this issue. 

1. Create a php file name passchange.php

2. Paste below code and save it.

<?php
include('config.php');
////////////////////////////////////////////////////////////////////

$username = 'username';
$newpassword = 'newpassword';

////////////////////////////////////////////////////////////////////

 
if ($userobj = get_record_select('user', "username='$username'", 'id, password')) {
    $userobj->password = md5($newpassword);
    update_record('user', $userobj);
    echo 'Password changed';
} else {
    echo 'Invalid username';
}

?>

3. Upload it to the Moodle root directory

4. From the browser, go to www.yourmoodleroot.com/passchange.php

5. Try to access your website with new password

6. Remove passchange.php from your webside

In reply to Sary Huang

Re: change admin's password

by Colin Fraser -
Picture of Documentation writers Picture of Testers

If all else fails and you can access the database via phpMyAdmin, go to the mdl_user table and copy the guest password into the Admin password field. It is encrypted, but the default password for Guest is "guest". You can then log in and change the password. That should get you out of trouble.

Average of ratings: Useful (1)
In reply to Colin Fraser

Re: change admin's password

by David Ulrich -

The easiest solution on this page so far! Took me 30 seconds. Thanks, Colin.

In reply to Colin Fraser

Re: change admin's password

by Anthony Rooney -

Hi

 

I have the same problem however I do not understand the solution mentioned. How to I run phpMyAdmin.  Where is this program and how is it launched?

 

Thanks

Anthony

In reply to Sary Huang

Re: change admin's password

by Gonzalo Rosetti -

I am having the same problem some of you have been describing: after and upgrade, moodle wouldnt let me in: so I need to restore my admin password.

 

I don't know how to manipulate the MySQL tables, so I have tried the script attached in the forum. However, it doesn't seem to work in Moodle 2.0

Will you please post a script like the one posted but updated to work in Moodle 2.0?

Do we have to change the username & newpassword in the first lines in the script?

Thank you for your help, which I desperately need!)

Gonzalo smile

In reply to Gonzalo Rosetti

Re: change admin's password

by Glenys Hanson -

Hi there,

In 1.9 this did the trick for me.

Insert:
d41d8cd98f00b204e9800998ecf8427e

as a password. Because MD5("") = d41d8cd98f00b204e9800998ecf8427e, so now your passoword is a empty string. Then login with nothing in the password field.

Thanks to Seiti Yamashiro - Tuesday, 20 March 2007, 11:08 PM

Cheers,

Glenys

Average of ratings: Useful (1)
In reply to Glenys Hanson

Re: change admin's password

by Andreas Panagiotopoulos -

Moodle v2 uses MD5??

I think it doesn't, but I would like someone to confirm it..

Thanks a lot

Andreas P.

In reply to Andreas Panagiotopoulos

Re: change admin's password

by Kenneth Barbour -

It uses md5.  If your config.php specifies a salt, it appends the salt to the end of the password string before digesting it.

Ex:
md5($password.$CFG->passwordsaltmain)

This would cause the md5 of your admin password not to match the one saved in the database.

In reply to Glenys Hanson

Re: change admin's password

by Michael Cohn -

Thank you, Glenys! I can confirm that this works in moodle 2, and that (as another commenter mentioned) if your install uses a salt, you have to temporarily remove it. The complete process (written as best I can for nontechnical users) is as follows:

1) open config.php. If there's a line that begins with "$CFG->passwordsaltmain", comment it out (i.e., put two slashes at the beginning of the line), then save.

2) go into the moodle database. In the table mdl_user, change the password to "d41d8cd98f00b204e9800998ecf8427e". If you are typing in queries directly, the command is:

update mdl_user set password='d41d8cd98f00b204e9800998ecf8427e' where username='admin';

3) Log in with the username admin and a blank password.

4) AFTER you're logged in, go back to the config file and put back the line you commented out, then save.

5) Go to http://my.moodle.org/admin/user.php and click on the admin user's name.

6) Change the password to whatever you want your new password to be. And you're done!

 

(explanation for non-technical users: a salt is a meaningless string that the system adds to your password before it encrypts it. Every installation of moodle has a different salt, meaning that if you encrypt the same password on different systems, the result will look different. That way, even if you choose a very common password, the encrypted version will be (effectively) unique. You need to remove the salt in order for us to be able to tell you what encrypted value you should enter in order to set your unencrypted password to blank. Then you need to put it back in order to keep your system secure.)

In reply to Michael Cohn

Re: change admin's password

by Michael Cohn -

If you have PHP, there's a much easier way to do this:

1) look in config.php to find out what your salt is.

2) In PHP, run this command:

echo md5('[YOUR SALT]');

3) Run the SQL command from the post above, replacing the password value with whatever value you got from the PHP command.

4) Your password is now a blank. You're done!

In reply to Michael Cohn

Re: change admin's password

by Inter Fan -

Thanks for this - upgraded to 2.2.3 and couldn't log in - now I can!

Really appreciate your help and your insturctions were really easy to follow.

smile

In reply to Gonzalo Rosetti

Re: change admin's password

by Anthony Rooney -

I've got the same problem and I do not understand why my perfectly good password is no longer accepted?

How do I fix?

In reply to Gonzalo Rosetti

Re: change admin's password

by Jay Shi -

Thank you for your help!  I managed to modify your passchange.php script for Moodle 2 as per below.

Moodle 2 script:

<?php
include('config.php');
////////////////////////////////////////////////////////////////////

$username = 'username';
$newpassword = 'newpassword';

////////////////////////////////////////////////////////////////////

global $DB;

if ($userobj = $DB->get_record_select('user', "username='$username'", array('id' => $password))) {   
$userobj->password = md5($newpassword);   
$DB->update_record('user', $userobj);   
echo 'Password changed';
} else {   
echo 'Invalid username';
}

?>

The changes were made using info from http://docs.moodle.org/dev/DB_layer_2.0_migration_docs

Average of ratings: Useful (1)
In reply to Jay Shi

Re: change admin's password

by ben reynolds -

Jay & Shane,

I've been following this thread since I began working with Moodle, but I never needed the script until I upgraded my localhost from 2.1beta to 2.1 and suddenly my admin password was no good.

Thanks so much for this script. Jay's 2.0 version worked beautifully.

In reply to Jay Shi

Re: change admin's password

by D K -

Unfortunately, after running the script, I see only the 'invalid password' line.  I am able to log on to the site using the 'empty' password hash; however, it is not possible to change the password in 2.1 profile as the 'current password' box cannot remain empty.  (Password policy in 'Security' settings has been switched off.)

Any help would be appreciated.

In reply to Jay Shi

Re: change admin's password

by earl albin -

I've tried every thing in all of these suggestions, none work. For instance I get errors in the " YOUR SALT" script, can't open file (in quotes is not the litteral, I copied verbatum what was suggested). I'm using version 2.1.

I'f anyone knows of a professioanl who can go into MySQL data base and recover my admin privaleges let me know. Short of that I'll have to completely re-install Moodle 2.1 and do my best to restore that. A disaster simply because the password recovery is overly complicated and not well though out. This is like a parachute without a rip cord. Othewise I love it!!!

In reply to earl albin

Re: change admin's password

by Max Monclair -

I have a situation that relates somewhat to this topic, where I am trying to automate the enrollment of students from a second database, after they have paid and ordered their textbooks.

I have a function that updates the mdl_users table well enough, and tries to create an MD5 hash using the salt string in my config.php. However, it is not being authenticated when I try using the login generated. I've been using a number of methods to try to enter a password the site could use, including trying the blank MD5 option. None seem to work.

Here's a possibly stupid question: what if I just commented out the salt value in the config.php? Would a straight string just be placed in the password field and read as such? While this is a security risk, I know, my client would much rather get this up sooner than later, even if there is less security.

In reply to Max Monclair

Re: change admin's password

by Max Monclair -

To follow up, my question WAS a stupid one, and I found that my authentication error had to do with a mistake in the code where I create the hash string. I had not escaped a character in my salt string that was throwing off the ColdFusion script I was using, thus creating a much different hash string than intended.

In reply to Alex Saevich

Trả lời: change admin's password

by david potter harry -

Moodle v2 uses MD5??

I think it doesn't, but I would like someone to confirm it..

Thanks a lot

Andreas P.

In reply to david potter harry

Re: Trả lời: change admin's password

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Older versions of Moodle used MD5. It now uses something better. It uses the password_verify and password_hash functions from the PHP standard library, with the standard has algorithm, which is bcrypt, which is pretty good. The code for this is in lib/moodlelib.php if you want to review it.

In reply to david potter harry

Re: Trả lời: change admin's password

by Guillermo Madero -

Hi David,

Since version 2.5 the methods use to handle passwords (hashing & salting) have changed. Stronger and better algorithms are now being used.

Average of ratings: Useful (1)
In reply to Guillermo Madero

Re: Trả lời: change admin's password

by Carolina Nolasco -

Hi Guillermo

i try with this 

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


in fact the password was changed in the db but when i try to login again, moodle return invalid login sad please could you help me?


thanks

Caro