As I was exploring which social networks to use next year, I tried out WordPress MU with Buddypress to complement Moodle, my course management system, on the advice of Christopher Rogers. Another teacher, Colin Matheson, and I both wanted to implement this but we also required a single-sign on, if possible, between the two so that we could have an easier time managing users and it would be less that the kids have to remember. After much research and experimenting, I figured out a solution that works for me. It may or may not work for your particular requirements.
What I was able to do is relatively simple. I set it so that I create student accounts in Moodle and disabled user registration. This will keep the course to only my students. When student accounts are created in Moodle, identical accounts are created in WPMU. Students accounts in WPMU are created as subscribers and they can then choose what to call their blogs in WPMU. Creating an account does not create an account in WPMU because I want students to be able to make a blog at http://blogs.jasontbedell.com/[title] as opposed to http://blogs.jasontbedell.com/[StudentName]. Account information is only editable in Moodle. I currently take the first name, last name, email, username, password, and description from Moodle and import it immediately into WPMU. It is not a true single-sign on since students have to sign on to both separately. I simply use the Moodle database and only create users there.
Step 1
You need to mirror your WordPress administrator account on Moodle because WPMU will not look at it’s own accounts once we’re done. So, if your WPMU username is Administrator and your password is securepassword, you nee to setup an administrator account on Moodle with the same credentials.
Step 2
You need either direct server access or ftp access to your Moodle installation. I use Filezilla on Windows and Linux. Cyberduck works great on Mac. Whatever you use, go to the main folder of your Moodle installation. Download or edit your config.php. Write down the following fields:
- dbhost =
- dbname =
- dbuser =
- dbpass =
You will need those fields for WPMU to gain access to Moodle’s database.
While you are in config.php, you need to turn off password salting. This is somewhat risky because you are removing an extra security layer, but I believe it should not be issue. There are 3 lines you need to edit. Find the line that begins with passwordsaltmain. There will be a very long, random text string. You need to edit out this line.
Beginning:
$CFG->passwordsaltmain = ‘xl&JnOK,~56tgdfyytd6/hhT.)u7uH,’;
End
/*
$CFG->passwordsaltmain = ‘xl&JnOK,~56tgdfyytd6/hhT.)u7uH,’;
*/
Now, you need to put that text sting in passwordsaltalt1 which should be the next line and make a new line called passwordsaltmain (Remember, you are editing php code. By adding */ and */ around a line, you basically make it invisible.) and leave it empty. So, the code should look like this in the end.
- */
- $CFG->passwordsaltmain = ‘xl&JnOK,~E;&SRi8NzpgHT.)uj0H,’;
- */
- $CFG->passwordsaltalt1 = ‘xl&JnOK,~E;&SRi8NzpgHT.)uj0H,’;
- $CFG->passwordsaltmain = ”;
Save your config.php and upload it to your Moodle server.
Step 3
It is best if you are starting with clean installations of Moodle and WPMU because this step will take less work. Go to you PHPMyAdmin. If you are using a database other than MySQL, it will be slightly different. Go to the user table in your Moodle database, probably mdl_user. You need to take your administrator password, go to this website, and run it through their MD5 hash generator. Take the output and put it in place of the password field of the administrator account in the database. This will make sense in a few steps.
Step 4
We are done with Moodle for now. Log into your WordPress or WPMU installation. You need to install a plugin called External DB authentication.There’s more information here: http://www.ploofle.com/tag/ext_db_auth/. Download, install, and activate the plugin.
Step 5
Under Settings on the WPMU administration page, go to External DB Settings. You should have all the info you need written down. For the External Database source fields, you should be able to get all of them from PHPMyAdmin. Make sure you choose MD5 as the password encryption method. What I used was:
Final Thoughts
This works well for me. I would like to get password salting working again. There is an option to use other for the password encryption and provide php code. We need to set $password2. $password2 = $password ; was in as an example. I thought that the following code would work.
- $password2 = md5($password);
- $salt = ‘xl&JnOK,~E;&SRi8NzpgHT.)uj0H,’;
- echo $password2;
- echo $salt;
I also tried it without the echo statements to no avail. I get odd errors on the page about unexpected “=” on line 1. I would love some help if anyone has any ideas. Thank you.

Pingback: How to implement SSO with moodle and wordpress blog? | deepinphp.com