Moodle and WordPress Single Sign On in 20 minutes – Part 1

It’s time to make WordPress authentication work on Moodle too.

For moodle 3.0, please see the comment from Carlos below, it takes a few changes in order to work on this new version of moodle.


WordPress installation and Moodle installation.
We are going to use the WordPress database in order to authenticate Moodle users. This way, we can sell courses using some wordpress ecommerce plugin and have instant access from customers.

The two sites are on the very same machine but on different domains (actually WordPress is in the “www.domain.tld” and “*.domain.tld” subdomains and Moodle is on another subdomain (courses.domain.tld) so we need to authenticate users in both sites using the very same database table.

The Problem:

The Moodle external autentication plugin does not work with WordPress authentication out of the box. To make it work, it will need a couple of modification very easy to make, don’t worry, even for a non php skilled person.
We will come back on this later on this post.

Let’s start our 20 minutes modification!

Shop list:

  • WordPress Version 3.4.2
  • WordPress database informations
  • Moodle Version 2.0
  • Moodle External Database Authentication Plugin (already in the Moodle default installation)
  • Some coding so, all stuff for ftp things/sftp/ssh things and a decent text editor with some failsafe feature (save a copy before modify etc)

That’s enough to start working on.

Once installed the two systems, you will have to properly configure the external database authentication plugin on Moodle platform. To do this you have to authenticate yourself as site administrator, then on the menubar choose and click on “Site Administration” -> “Plugin” -> “Authentication” -> “Manage Authentication”.

You can use the provided image on the left to quickly find out the links path needed to get there.




Once there you will see a list of all authentication plugin, their status (active or inactive) their priority order and the link to their “settings”. As you can see in the image below, you have to enable and prioritize the plugin in order to make it work. You probably want to disable the self-registration (see picture in bottom part) feature in order to prevent user to signup using moodle platform because, otherwise, all users created within Moodle will not be able to authenticate against WordPress.

This is the list of the moodle authentication plugins. It shows if a plugin is enabled or not, and it exposes a link for each plugin to be configured.

Once you have done, let’s click on the “Setting” link and let’s try to configure this plugin the best we can.

We have to enter all info used by Moodle to read the WordPress database.
Fields are:

  • Host, in my case i will use “localhost” and probably you too unless your db is hosted on a different machine, in that case you have to use the Hostname or ip address of that machine
  • Database, in my case “mysqli” (Please, notice the trailer “i” – mysqli and not mysql).
  • Use sybase quotes, we do not need this to be on so we will leave it on “NO
  • Db name, the name of your wordpress database (get it from wp-config.php)
  • Db User, mysql user that can access WordPress db tables
  • Db Password, mysql password for mysql user
  • Table, the name of the table where username/passwords are stored. The most of the time is “wp_users” unless you changed your table prefix
  • Username Field, the field containing the username, for WordPress: “user_login”
  • Password Field the field containing the password for username for WordPress: “user_pass”.
  • Password Format, we should choose “wordpressformat but there is no such option in this drop down, so what? we will solve this later, don’t worry
  • External db encoding, i use “UTF-8″
  • SQL setup command, you can leave it blank
  • Debug ADOdb, choose “NO
  • Password-change URL, we use the wordpress password recovery page link

These are the needed field to make this thing work, if you want more integration, you can configure the part named “cron syncronization script” and sync information such as first name, surname, user preferences and so.

But now we have to stay focused on the missing dropdown item and find a way to get it out of there.

We need to modify the file in /auth/db/config.html and change this (at line 190)

$passtype = array();
$passtype["plaintext"] = get_string("plaintext", "auth");
$passtype["md5"] = get_string("md5", "auth");
$passtype["sha1"] = get_string("sha1", "auth");
$passtype["internal"] = get_string("internal", "auth");
echo html_writer::select($passtype, "passtype", $config->passtype, false);

to this

$passtype = array();
$passtype["plaintext"] = get_string("plaintext", "auth");
$passtype["md5"] = get_string("md5", "auth");
$passtype["sha1"] = get_string("sha1", "auth");
$passtype["internal"] = get_string("internal", "auth");
$passtype["wordpress"] = "wordpress";
echo html_writer::select($passtype, "passtype", $config->passtype, false);

This modification will make “WordPress” authentication drop down item available, but still not working.
We need to process the password with this class: class-phpass.php [Phpass Website].
This class, can actually process passwords the same way wordpress does, so this is the missing link to make sso work.
Just copy the file class-phpass.php in your /moodle/lib folder
And then add this line right after other requires at the beginning of wp-login.php to moodle/auth/db/auth.php:


To make our modifications work we need to add a few lines of code to the file /auth/db/auth.php, it’s easy. Open the file and go about line 90, you should see something like this:

if ($this->config->;passtype === 'md5') {   // Re-format password accordingly

$extpassword = md5($extpassword);

} else if ($this->config->;passtype === 'sha1') {
$extpassword = sha1($extpassword);

Now, let’s do our final modification and right after the lines here, add this code:

else if ($this->config->passtype === 'wordpress') {
$hash =new PasswordHash(8, false);
$rs = $authdb->Execute("SELECT * FROM {$this->config->table}
WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'");
$check = $hash->CheckPassword( $extpassword, $rs->fields["user_pass"]);
return $check;

If you are as lazy, you can download a copy of both file here, but i strongly suggest you to make modification by hand because time goes by and releases change.

Moodle auth with wordpress

Now, finally we can come back to the settings page and add “WordPress” as “Password format“.

All you have to do to try if this works, is to logout from wordpress, signup into wordpress as new user, and then go and authenticate with the same credentials against Moodle. If all work you will be redirected to the user profile page on moodle where you can complete your profile with your informations. 

Incoming search terms:

  • moodle wordpress (30)
  • wordpress moodle integration (26)
  • wordpress moodle (22)
  • moodle single sign on (16)
  • moodle wordpress integration (16)
  • wordpress sso (14)
  • wordpress single sign on (12)
  • wordpress and moodle (11)
  • single sign on moodle (11)
  • wordpress and moodle integration (10)
(Visited 42,765 times, 7 visits today)

Author: Giuseppe Urso

Giuseppe lives in Haarlem now with his shiny dog, Filippa In 1982 received his first home computer, a Commodore 64, followed by Datasette and a 1541 Floppy Disk Drive. In 1999 he installed his first Linux distro (LRH6). In 2006 he switched to Debian as favourite OS. Giuseppe Urso actively sustains the Free Software Fundation and his founder Richard Mattew Stallman, he speaks to people trying to convince them to join the fight now, and about how important is to use Free Software only. He has a job as Infra Specialist at Hippo Enterprise Java Cms an Open Source Enterprise class Content Management System, one of the coolest company ever, in Amsterdam. He's always ready to install Debian on other people computers for free.

109 thoughts on “Moodle and WordPress Single Sign On in 20 minutes – Part 1”

  1. Hi Giuseppe,
    Nice concept. Instructions are easy to follow and 20 minutes to set up. However, my setup failed. I did a clean install of both WP and Moodle. Checked both db for user. WP has my user in the db but Moodle db does not. I’m not getting any errors but obviously nothing was coded for that scenario. My db is using localhost as well and all username and pw are correct. Any ideas what might be the problem?

    ~cheers, Matt

    1. Ok,
      First thing i would look at is in the moodle administration, to verify that the choosen method from the dropdown is “WordPress” as it means that modifications made to /auth/db/config.html (at about line 190).
      If you already did it succesfully, you should see the “wordpress” in the password type dropdown.
      If it is so, you can see “wordpress” in the dropdown, but it doesn’t mean it actually works, because you have also to modify /auth/db/auth.php at about line 90 in order to make this works.
      If you already did it but still it does not work, you can temporarely use some short lines of code to debug
      you can download the attached files (the two with modifications) and try to replace yours.
      My only concern is about the update in moodle released right after my article.
      That’s why if i were you i would check firts these two files against the ones on the new release and possibly we can try to fix it for the newest release too.
      Hope this can really help, and please update about your progress.
      doi doi

    2. Hey Matt, i just found what the problem is. I’t’s my fault, i’m sorry, because i missed the entire part about phpass.
      You need it (not within moodle distro) because you cannot process passwords as wordpress does. With this class you will be able to get the SSO.
      Keep in touch

    3. And then add this line right after other requires at the beginning of the file:

      Where do I have to add this line. In which file and where inside this file “right after other requires”.

      As I see author not checking comments here anymore, so maybe somebody else can help in this case?

      1. Hi i’ve been a little busy with my new job… I don’t usually neglect my blog, it’s just… It has a little hard in last 2 months because I’m working in the Netherlands (I’m Italian) and this is my very first time abroad… Now I’m getting confident day by day (thanks to very nice collegues), so i will be more present on this blog.
        By the way the file you are supposed to paste the require_once statement is “wp-login.php”.
        Sorry i forgot to mention it.


  2. Hi Giuseppe,

    First of all thanks for this tutorial, i got it working in under 20 minutes 🙂

    Was wondering if you were still going to do a second part for this that wouldn’t require a person to login twice, that would be wonderful.

    On a side note the link for phpass was not working but i ended up using this one: (probably not the best idea but did the job)

    Again, muchly appreciated!

  3. Hi there,
    I do have the same question like Yousuf:
    In which file do I have to add this require_once($CFG->libdir.”/class-phpass.php”); ?

    Btw the link to Openwall doesn’t link to the correct file anymore 🙁

    Thank you and best regards,

  4. Hi Giuseppe

    I am having a problem similar to others. Have got the phppass file, but do not know where to insert the line of code, as there are no other requires that I can find in the file …

  5. Hi
    Thanks for the information.

    –> Created all the above steps sucessfully.
    –> All External users are now login with their Exisisting wordpress username & passwords.
    –> but the problem is i am unable to see the users in moodle list of users

    Thanks for the Help in Advance

    1. Did you configure Moodle so external users are imported as well?
      Some time has past but i can remember that somewhere i had to map wordpress user fields with moodle user fields, thus as soon as a new user logon on moodle checking credentials against wordpress database his data are transfered on moodle db…
      I’ll take a look and I’ll let you know.

  6. Great post Giuseppe, going to give this a try later today i think. Any plans to create the second post you mention?

    I’m very surprised that a plugin for WP/Moodle hasn’t been developed for this yet. I’ve used Moodle and Joomla together using Joomdle ( – I’d love to see a similar plugin or WP!

    1. Hi, i honestly don’t know if and when i’ll do it. I think that my approach wasn’t correct.. I mean it works until now, but maybe it would have been better to think at ldap…
      What do yuo think?
      Could it be a solution? I’m pretty sure there is something for both wordpress and moodle so they can be used with ldap…

  7. Hi and thanks for your help.

    I found the class-phpass.php on the web
    Then I copied to /moodle/lib folder

    But my problem is the next step:

    And then add this line right after other requires at the beginning of the file:

    Where do I have to add this line. In which file and where inside this file “right after other requires”.



  8. Hi!
    When I put the line require_once($CFG->libdir.”/class-phpass.php”); on my wp-login.php file, it shows this error:

    Warning: require_once(/class-phpass.php) [function.require-once]: failed to open stream: No such file or directory in /home/storage/b/5f/4a/site13670345/public_html/curso/wp-login.php on line 12

    Fatal error: require_once() [function.require]: Failed opening required ‘/class-phpass.php’ (include_path=’.:/usr/share/pear’) in /home/storage/b/5f/4a/site13670345/public_html/curso/wp-login.php on line 12

    Do you know what could had happened?

    Tks so much,

    1. It looks like you’re missing the file in that location. Personally i took a quick look at mine and i have:
      require_once( ABSPATH . ‘wp-includes/class-phpass.php’ );

      As you can see i have “ABSPATH . ‘wp-includes/” in place of $CFG->libdir.blah
      If I’m not wrong an update in wordpress messed my post right after a couple of day after i wrote it.

      In a few words: try as I did. Let me know.


  9. Pingback: Moodle and Wordpress Single Sign On in 20 minutes – Part 1 : Giuseppe Urso Blog | Wasamara
    1. Actually,

      All sorted, just copied the file from an old version of WordPress I had here locally 🙂


  10. Hey Giuseppe,

    Great work. But shouldn’t the following line:

    And then add this line right after other requires at the beginning of wp-login.php:

    Read as:

    And then add this line right after other requires at the beginning of lib/db/auth.php:


  11. Hey giuseppe,

    Great Work..!!

    I have a question –
    Can we do the same in vice versa – using the moodle database, authenticate users in wordpress., If so need the procedure for doing it.

    Also, waiting for the SSO too…!!

    1. I can’t tell right now, as it i hard to remember details, but when i started i was 100%free and if i went this way there has been one reason. Probably the other way around is harder than this.

  12. Excellent step-by-step guide, but I noticed a typo I think. In the section on adding the required “class-phpass.php” authentication class, you said to make the change in “wp-login.php”. I think that should instead read “auth.php” since we’re adding the WordPress authentication class within Moodle, not making any changes to WordPress itself. If you have trouble finding the “class-phpass.php” on its because that project recently changed their site structure (old download links may be dead and the authentication class is now called “PasswordHash.php”), but to be sure you’re using the same version as WordPress, just copy and paste the code from “wp-includes/class-phpass.php” that way you can be sure you’re using the same auth code).

    The other little thing was that in the latest version of Moodle, the addition of the “else if” statement to catch “wordpress” logins should be placed on line 113 instead of line 90.

    Anyway, those little changes aside, it worked for me as of latest versions of both WordPress and Moodle in October 2013 so thanks a bunch!

    Lastly, I noticed this article is labelled as “Part 1”, is there a Part 2 on “automatically logging in using your now synched-up login credentials” to have it so that a login activity in WordPress automatically fires a login action to Moodle?

    If it exists or if you can make one, a several beer donation is indeed headed your way!!! I’m just not sure if its possible to automate that (maybe hidden Moodle form field added to “wp-login.php” with Javascript auto-fill of values and asynch POST)?

    1. Hey BSC, I followed your small changes and I still can’t this to work. Not sure why I’m having trouble. Any thoughts?

  13. Hey there, I have tried to implement this, but having trouble with the


    as soon as I input this line into auth.php I get white screen when trying to access the login page. I’ve followed the other steps to the T, but seems this step is giving me issues and not sure what to do.


    1. Hi, white page means that you are not showing errors. try to check logs, and see. It usually is a typo or something similar. You are just not seeing the error.

  14. I have been searching for this kind of data for a long time, but I was struggling
    to get a dependable source so far. Thx.

  15. Hi Giuseppe,

    Thanks a lot for the post. It worked (not form the first time but it did).

    Unfortunately it hasn’t solved my problem as I need to send users to moodle via log in form in wordpress. For now my users have to log in twice while the idea is:

    1. log in via wp only
    2. redirect logged-in user straight to moodle (user is not supposed to see wp user panel)

    Could you suggest any solution?

    Thanks a lot in advance.


    1. Hi Valeria, i have few minutes right now, but let’s say that: since i wrote that code a lot of time has passed but at same time i see the topic is still kind of “warm” not to say “hot”.
      Plus i received some request/donation for this.
      So i was thinking to start a somehow “official” project on git or google code in order to maintain it through wp and moodle updates. Next weekend I’ll start gathering all the pieces and we will figure out a way to make it work (at least on the wp side) like a plugin, creating some menu to control options like your point 2.
      That will make us cooperate as normally happens in free software environment, keep the code up to date, and make easy for non tech people to use it as well.
      I’ll update the post with this info. You should receive an email then so we could start working together with all others involved into this.
      Giuseppe 😉

      1. Hi Giuseppe,

        Happy to hear that. 🙂

        I found a temporal solution, added a login form into WP that brings user directly in Moodle right after logging-in. Also I changed the email that WP sends to the user after registration adding there a link to that special login page in WP.

        Obviously, these changes are going to dissapear after new WP update. So to have a plugin that does all the job and does it better would be super cool for all who use WP and Moodle. 🙂

        1. Nice! Yes you got the point: make changes survive to wp updates. That’s achievable with making it work as plugin.
          Anyway as said, let’s see this weekend what can be done this way

  16. Hi Guiseppe,

    Great post.

    I understand you are really busy, apologies for nuisance factor. I am getting the following error:

    Parse error: syntax error, unexpected T_CLASS in /websites/123reg/LinuxPackage23/vi/ta/li/ on line 13

    on line 13 I have:

    require_once( ABSPATH . ‘wp-includes/class-phpass.php’ );

    Can you shine any light on it?

    Thank you in advance.


    1. Maybe I’m wrong but it seems to me that you are using backticks ( ‘ ) on place of single quotes ( ‘ ).
      This usually happens because of copy/paste from such a blog platform.

      Could you try to replace them and tell me if it works?


    2. Hi Guiseppe,

      Excellent, it worked.

      A lesson learned for me, always paste as plain text!

      Thank you.

      You’re a star.

  17. Hi Giuseppe,
    I am new to moodle and wordpress.
    I followed all your steps as mentioned but the problem is that when I login to moodle,
    I am in “index.php” blank page.
    Please help me to solve this issue. I cannot sort out where I have missed the step.

    1. Completely blank page could mean that your php setup is not exposing error. And at same time maybe a typo has been made.
      You can either enable error reporting or check the error log.

      Let me know if this helps otherwise we will figure out another way.


  18. Hi Giuseppe,
    I created wordpress site then linked moodle courses which will redirect users to moodle. But I was wondering if I can bring whole content of moodle(e.g. Courses, Quizzes, other stuffs…) to my wordpress page.
    Is it possible?
    If yes then please shed some light over this. I would be much grateful to you.
    Thanks a lot in advance.

    1. Hm, the Moodle contents within WordPress you say… Not sure if I’m understanding your request.
      Are you asking how to make the two websites using the same graphic theme?
      If so, you can try copy some css from wp to moodle and adapt images and html to it. But this is the way for not being able to keep your moodle up to date. If you modify php pages and so, next update will overwrite your changes… Is this what you are saying?

      Let me know

      1. Hi Giuseppe,

        I wanted to bring contents of my moodle page to wordpress page. But I guess I can make this work using web services.
        I m searching on it. I will definitely share with if I can find anything.
        Do you have any idea about this?

        Would love to hear from you.
        Thanks again.

  19. Hi there,

    Thank you for such clarity in your instructions but I am stuck!

    I have reached the place
    Just copy the file class-phpass.php in your /moodle/lib folder

    I am working with moodle 2.5.4 and phpass.php doesn’t seem to be held in moodle/lib folder can you help me please?


    1. Exactly.
      You need to copu the mentioned file on the mentioned path in the moodle installation inorder to make it use that file during password processing.
      You need to copy it there because it isn’t there.


  20. Hello there again

    I am also stuck on this bit

    Now, finally we can come back to the settings page ad add “WordPress” as “Password format“.

    What do you mean? I can see anything relating to password format.

    Many thanks sarah

    1. I mean: after adding the previous lines of code, if you go on the settings page, you will find a new option in “password format” which should be wordpress

      1. Thank you so very much for
        You reply. I will get to work and see if I can complete this with your clear instructions SARAH x

  21. Hi,

    Is there any way to synchronize all my wordpress users to moodle. because i am not able to enroll specific wordpress users to moodle cources.

    here it is happening like first user need to fill the profile in moodle, then admin able to see the user in user list,

  22. Hi Giuseppe

    Thank you for this blog. May I ask if you know how easy/difficult it would be for me to have my ecommerce that I have setup in my wordpress to take the money for my courses in my moodle site.

    Objective client visits wordpress, buys course in ecommerce, accesses course.

    Thank you x

    1. Hi, I have done this some times ago, it was not that diffioult.
      You should manage to get sso working first, then manage the ecommerce products as subscription and make them work for courses. In aother words after the sso works you have users in moodle db. Then you have to mod your ecommerce plugin or mod in order to grant the user on the moodle side access to the course.

      It can be not exactly easy, but doable.


  23. Hi,
    I’m wondering if I’ve missed a step. I’m receiving this message when I try to log in with a login that should be checked in my external database:

    Fatal error: Class ‘PasswordHash’ not found in /moodle/htdocs/auth/db/auth.php on line 115

    Here is what my auth.php looks like, lines 114 to 120:
    else if ($this->config->passtype === 'wordpress') {
    $hash =new PasswordHash(8, false);
    $rs = $authdb->Execute("SELECT * FROM {$this->config->table}
    WHERE {$this->config->fielduser} = '".$this->ext_addslashes($extusername)."'");
    $check = $hash->CheckPassword( $extpassword, $rs->fields["user_pass"]);
    return $check;

    I’d appreciate any suggestions. BTW, my Moodle and WordPress site are on different servers. When I test settings on Moodle for External Database Connection, it does work. I’ve also used BCMoney’s suggestions about copying the phpass from wordpress.

    Thanks for putting together this tutorial!

  24. Hi Jeff,
    Your approch to the solution is very good. I think we can work on this and make some improvments.

    The only error in the posts is that you have mentiond “require_once($CFG->libdir.”/class-phpass.php”); should go in “wp-login.php”.

    But I think that this code needs to go into file “auth.php”. I have tried and tested, it is working fine.

    The good thing about your solutions is that a user does not need to make any code changes on wordpress site at all. All work needs to be done on Moodle.

    I am going to make more checkes and will update you on this.

    1. Hi Gajala

      “require_once($CFG->libdir.”/class-phpass.php”); ”
      I added this code in file : auth/db/auth.php.. It’s working.

  25. Hi Giuseppe,

    like the others I googled a long time for finding a SSO-solution. I found your site and got your code working with this comment: Thinking on the code for SSO and searching via google I found another great solution.

    Do you have seen the ‘wordpress to moodle single sign on’-solution by frumbert? It signs you into moodle from within wordpress via a shortcode and works with 2 plugins, one for wordpress and one for moodle: (install on moodle)–wordpress- (install on wordpress)

    It works! 🙂

    Greets from Germany!

  26. Hi, I know this is an old post, but I am having the same issue as David, can’t figure out what is wrong. This is the error I am receiving.

    Fatal error: Class ‘PasswordHash’ not found in “tutorials/auth/db/auth.php on line 114”

    1. The file tutorials/auth/db/auth.php is trying to use a class called PasswordHash which is missing from the file(s) processed by php. In other words you should make sure that you included the right file into the right file.

      If I´m not wrong this has been already discussed some comments before.
      Check carefully this steps:
      Just copy the file class-phpass.php in your /moodle/lib folder
      And then add this line right after other requires at the beginning of wp-login.php:


  27. I got it to work by putting: require_once($CFG->libdir.”/class-phpass.php”);
    Into auth.php on moodle, not in wordpress.

  28. Still ,a problem persists… If i login via word press as admin , will it login automatically into moodle? and if a new user is created in word press , will the same user information be saved in moodle DB ?

  29. Hi , I am new to moodle and wordpress, . My question is if i login to wordpress, will it redirect me to moodle main page without another login authentication . If i register in wordpress , will the same user details be saved in wordpress?

  30. These instructions are confusing because they are slightly wrong.
    This line:
    And then add this line right after other requires at the beginning of wp-login.php:
    should say:
    And then add this line right after other requires at the beginning of auth.php:

    the same file you edit later in the instructions. You need to add the wordpress password class to that file so that file can interpret the passwords in the same way as wordpress does. ALSO you don’t need to download that class-phppass.php file from the net, its right there, in your wordpress install!

  31. hy, im trying to integrate WP and MOD with Single Sign On.. but then at the very first step i did not get which one to install first either WP or MOD? and also i can imagine that i will encounter situation of using LOCALHOST both of them…is it true? Or i really missed small important step on this tutorial? Please guide me from the beginning.. sorry for my bad english

  32. For waiting awhile admin or somebody answering my question.. i decide to work on and install WP 3.4.2 first as what i did before using other tutorial which said to instal MultiSite WP first (but i failed to do so).. so now i will just do a clean installation on WP 3.4.2 first

  33. Hello,

    Thanks for all of the work you have put into this! It’s working perfectly. I only had one question. I am currently using the wp2moodle plugin for wordpress/moodle on a testing server. It works great as well, however it doesn’t pass the user’s credentials over to the moodle database, unless, the user clicks a link and enrolls into the cohort that was pre-established by the administrator. I am wondering if there is a way to utilize both options so that, for example, I could sell a course to students and afterwards they could click a hyperlink that would automatically enroll them to the course and pass the username and password, or they could simply register and then login with those same credentials in Moodle. Is it possible to do both? I have tried to use your SSO authentication method as well as Frumpert’s wp2moodle plugins, but it is saying that there is an error writing to database.

    Thanks in advance.

  34. Hi Guiseppe,

    Thank you so much to your step by step tutorial. It’s work fine with moodle 2.7 and WP 3.9.
    You describe how to do with Moodle External Data Base Authentifcation to link WP and Moodle.

    But how can we do to set up “auto enrolment” with WP (for example woocommerce products) and moodle course ?

    Best regards.

  35. Hi Giuseppe,

    Great post. We have worked on many of our client project that involved integrating Moodle and WordPress together. From our experience, we have written a post on why people prefer Moodle and how WordPress overcomes Moodle’s limitations.

  36. thanks for that great post,
    i just followed the instruction as said, and i didn’t get any errors
    but when i try to login, i get the invalid credentials message !!

    BTW i have Tested the settings of external database and it works fine

  37. Hello,

    First of all, thanks a lot for such tutorial.

    Even I included successfully class-phpass.php I am having an error


    Notice: Trying to get property of non-object in …/moodle/auth/db/auth.php on line 139

    139: $check = $hash->CheckPassword($extpassword, $rs->fields[“user_pass”]);

    any ideas?

    1. I too am getting this same error since Moodle 2.9 and WP 4.2.2

      I’m wondering if something else has changed??

      I am cutting and pasting the code so I don’t think its a typo.

      1. If you’re copy/pasting code you could have some problem with some chars. To avoid those, copy and paste it in a text editor, then you can easily check whether some weird chars are present. Usually the single quotes are a bit messed up when copied form an html output.

        1. Thanks for replying. The code worked for us but recently since moodle2.9 we get this error. That is why I think something might have changed on the moodle side.

          Here is our error:

          Notice: Trying to get property of non-object in /home/xxxxxxxxx/public_html/moodle/auth/db/auth.php on line 143


  38. For a while now, Moodle has been the world’s most popular open-source learning management system. Lately, however, Moodle is becoming rather stale. Unless you are a skillful programmer, removing the clunkiness that Moodle has out-of-the-box can be quite the task Managed Moodle Hosting.

  39. Hi, I followed all the steps mentioned above, now I’m able to login using wordpress and use Moodle dashboard. But how can I make my Moodle courses as products of woocommerce.

    1. Hi, I don think you can do that dynamically. I mean not in a way that you create a course and it pops up in some ecommerce plugin. You better choose a good ecommerce plugin (like woocommerce) and use some kind of api-wise system in a way that as soon as the course is paid, the user is created and granted access to the course. This is not that easy though, but if you succeed you’ĺl end up with something that a lot of people would like to have.

  40. Hello Giuseppe,

    Have you created a plug-in for the WordPress to Moodle single sign-on? I did not see this on the site.

    Thank you!
    Dori Jones

  41. can i konow where is the file class-phpass.php . i cant find in my moodle directory..??? please help i am newbie to moodle and wordpress

  42. Hi Giuseppe,

    I’ve been using your solution up to Moodle 2.8, with no turbulence. Thank you!
    On Moodle 3, however, there were a few changes in auth/db/auth.php which allowed the patch for that file to shrink to a smaller format:

    You just need to find this chunk of code on that file (auth.php). On Moodle 3.0 it starts at line 132:

    if ($this->config->passtype === ‘plaintext’) {
    return ($fromdb == $extpassword);
    } else if ($this->config->passtype === ‘md5’) {
    return (strtolower($fromdb) == md5($extpassword));
    } else if ($this->config->passtype === ‘sha1’) {
    return (strtolower($fromdb) == sha1($extpassword));
    } else if ($this->config->passtype === ‘saltedcrypt’) {
    return password_verify($extpassword, $fromdb);
    } else {
    return false;

    And then you add these five lines just above the third line from the bottom (that which says “} else {“). Notice that it includes the “require_once” line, so this wil be the only change to be made on that file:

    }else if ($this->config->passtype === ‘wordpress’) {
    $hash =new PasswordHash(8, false);
    $check = $hash->CheckPassword( $extpassword, $fromdb);
    return $check;

    On Moodle 3.0 these will be lines 141 to 145. That is all you need to change on auth/db/auth.php

    Thank you again for sharing your solution, back in 2010!

    1. Hi Carlos, unfortunately I’m quiet busy, I’ll try anyway to update the guide according to the new version of wordpress and moodle, not sure when though.


  43. Hi Giuseppe,

    I tried to use the above in Moodle 2.9.1. I disabled the “Self registration” and changed the contents for the “external database”.

    Now at the very end I wanted to choose “wordpress” from the download. However, the window with authentication mathods does not come up anymore. Is this possible due to the fact that I did not able the “external database”option? If so, do you have any idea how I can recover this?

    Thanks in advance.

    1. It’s not completely clear at what point you got stuck, can’t you revert your changes? As i mentioned in previous comments, since i wrote the guide several new versions (minor and major) of both WordPress and Moodle have been released, this can also be the reason why some of the steps must be reviewed and possibly fixed.


      1. In the solution of Carlos, remove the line require_once($CFG->libdir.’/class-phpass.php’);

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.