diff --git a/classes/loginflow/authcode.php b/classes/loginflow/authcode.php index 82fcd54..1885865 100644 --- a/classes/loginflow/authcode.php +++ b/classes/loginflow/authcode.php @@ -607,8 +607,8 @@ protected function handlelogin(string $oidcuniqid, array $authparams, array $tok // Handle username change - update token, update connection. if ($usernamechanged) { $potentialduplicateuser = core_user::get_user_by_username($oidcusername); - if ($potentialduplicateuser) { - // Username already exists, cannot change Moodle account username, throw exception. + if ($potentialduplicateuser->id!=$tokenrec->userid) { + // Username already exists in another user, cannot change Moodle account username, throw exception. throw new moodle_exception('erroruserwithusernamealreadyexists', 'auth_oidc', null, null, '2'); } else { // Username does not exist: diff --git a/lib.php b/lib.php index 17cf0d1..c8f6734 100644 --- a/lib.php +++ b/lib.php @@ -177,7 +177,7 @@ function auth_oidc_get_tokens_with_mismatched_usernames() { FROM {auth_oidc_token} tok JOIN {user} u ON u.id = tok.userid WHERE tok.userid != 0 - AND u.username != tok.username'; + AND u.username COLLATE utf8mb4_general_ci != tok.username COLLATE utf8mb4_general_ci'; $records = $DB->get_recordset_sql($sql); foreach ($records as $record) { $item = new stdClass();