Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Conver usernames to lowercase for internal use. This prevent duplicat…

…e users

when using external authentication and posgresql.
  • Loading branch information...
commit 1e22bc9c04eefece0ddc3d2267145d457cdfac79 1 parent e40488f
authored April 24, 2003
3  lib/moodlelib.php
@@ -489,7 +489,8 @@ function get_moodle_cookie() {
489 489
 function create_user_record($username, $password) {
490 490
 /// Creates a bare-bones user record 
491 491
     global $REMOTE_ADDR, $CFG;
492  
-    
  492
+    //just in case check text case
  493
+    $username = trim(moodle_strtolower($username));
493 494
     if (function_exists(auth_get_userinfo)) {
494 495
         if ($newinfo = auth_get_userinfo($username)) {
495 496
             foreach ($newinfo as $key => $value){
2  login/index.php
@@ -21,8 +21,8 @@
21 21
 
22 22
 
23 23
     if ($frm = data_submitted()) {
  24
+        $frm->username = trim(moodle_strtolower($frm->username));
24 25
         $user = authenticate_user_login($frm->username, $frm->password);
25  
-
26 26
         update_login_count();
27 27
 
28 28
         if ($user) {
19  login/signup.php
@@ -6,7 +6,7 @@
6 6
 
7 7
     if ($user = data_submitted()) {
8 8
         validate_form($user, $err);
9  
-
  9
+        $user->username= trim(moodle_strtolower($user->username));
10 10
         if (count((array)$err) == 0) {
11 11
             $plainpass = $user->password;
12 12
             $user->password = md5($user->password);
@@ -74,16 +74,17 @@
74 74
 
75 75
 function validate_form($user, &$err) {
76 76
     global $CFG;
77  
-    if (empty($user->username))
  77
+    if (empty($user->username)){
78 78
         $err->username = get_string("missingusername");
79  
-
80  
-    else if (record_exists("user", "username", $user->username))
81  
-        $err->username = get_string("usernameexists");
82  
-
83  
-    else {
84  
-        $string = eregi_replace("[^([:alnum:])]", "", $user->username);
85  
-        if (strcmp($user->username, $string)) 
  79
+    }else{
  80
+        $user->username = trim(moodle_strtolower($user->username));
  81
+        if (record_exists("user", "username", $user->username)){
  82
+            $err->username = get_string("usernameexists");
  83
+        }else {
  84
+            $string = eregi_replace("[^([:alnum:])]", "", $user->username);
  85
+            if (strcmp($user->username, $string)) 
86 86
             $err->username = get_string("alphanumerical");
  87
+        }
87 88
     }
88 89
 
89 90
     if (isset($CFG->auth_user_create) and $CFG->auth_user_create==1 and function_exists('auth_user_exists') ){
2  user/edit.php
@@ -45,7 +45,7 @@
45 45
 	if ($usernew = data_submitted()) {
46 46
         $usernew->firstname = strip_tags($usernew->firstname);
47 47
         $usernew->lastname  = strip_tags($usernew->lastname);
48  
-
  48
+        $usernew->username = trim(moodle_strtolower($usernew->username));
49 49
         if (empty($_FILES['imagefile'])) {
50 50
             $_FILES['imagefile'] = NULL;    // To avoid using uninitialised variable later
51 51
         }

0 notes on commit 1e22bc9

Please sign in to comment.
Something went wrong with that request. Please try again.