Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-46642

external db authentication, sync_users.php cli script is case-sensitive in username

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 2.5.6, 2.7.1
    • Fix Version/s: None
    • Component/s: Authentication
    • Labels:
      None
    • Affected Branches:
      MOODLE_25_STABLE, MOODLE_27_STABLE

      Description

      This may not be a real bug if case-sensitivity is on purpose but we've recently started running the /auth/db/cli/sync_users.php script.

      With it we get a whole series of
      "Error inserting user"

      I was able to track the problem down to this. Existing users in Moodle that were created when they first logged in, had entries in mdl_user as such:

      username: samplename@hotmail.com
      email: samplename@Hotmail.com

      Note the different casing of hotmail vs Hotmail in the username vs email.

      In our external db, the email and username are both: samplename@Hotmail.com

      It looks like the problem is the sync script considers the non-matching casing as a different user, then tries to create the user again and fails.

      We are on 2.5.6, but I think it also affects 2.7, judging by the code on github. We are able to work around this for now by changing the casing of the email field in our external db to be all lower case, but it would be better if it the sync_users script was not-case sensitive when the username in moodle appears to always be stored lower case and the login form is also case-insensitive.

      The piece of code that would need to be tweaked for 2.7, I think is line 376 of /auth/db/auth.php, where the array_diff does a case sensitive comparison.
      https://github.com/moodle/moodle/blob/7784c3ad18371607780f2845d44db291112b816e/auth/db/auth.php#L376
      $add_users = array_diff($userlist, $usernames);

      For 2.5 it is line 370 of the same file.
      https://github.com/moodle/moodle/blob/MOODLE_25_STABLE/auth/db/auth.php#L370

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              mgancarzdsi Mathew Gancarz
              Participants:
              Component watchers:
              Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: