Authentication

How To Remove Non-Default Authentication Plugins

If you can't login to a copied Moodle because the authentication plugin does not match your local situation, go to the database. Execute this sql statement:

UPDATE mdl_config SET value = 'manual' WHERE name LIKE 'auth';

Now the authentication plugin is set to the default plugin.

In some cases, such as for a Moodle copy which was originally using a CAS server, it may also be necessary to update the mdl_user table:

UPDATE mdl_user SET auth = 'manual';

Remove https login:

UPDATE mdl_config SET value =  '0' WHERE mdl_config.name LIKE 'loginhttps';

And finally, some systems may use an alternative login url which you should delete:

UPDATE mdl_config SET value = '' WHERE name LIKE 'alternateloginurl';

And now all at once:

UPDATE mdl_config SET value = 'manual' WHERE name LIKE 'auth';
UPDATE mdl_user SET auth = 'manual';
UPDATE mdl_config SET value = '' WHERE name LIKE 'alternateloginurl';
UPDATE mdl_config SET value =  '0' WHERE mdl_config.name LIKE 'loginhttps';

Don't forget to empty the cache folders in moodledata!

Restore Deleted Users

Whenever you delete a user in Moodle, the mdl_user.deleted column is set to 1. But that's not all:

  • username is set to
    "$user->email.".time();
  • email is set to md5 hash of the new username

So to restore the user, you need something like the following:

-- Restore deleted users (Search for a dot [.], starting from the right of the string, return substring till right-most dot)
UPDATE IGNORE mdl_user AS u SET deleted = 0,
username = SUBSTRING(u.username, 1, (LENGTH(u.username) - POSITION('.' IN REVERSE(u.username)))),
email = u.username
WHERE deleted = 1

The IGNORE keyword means: skip all problematic updates (e.g. duplicate key), but do perform the other updates.


Personal Tools