Skip to content

Commit

Permalink
Conver usernames to lowercase for internal use. This prevent duplicat…
Browse files Browse the repository at this point in the history
…e users

when using external authentication and posgresql.
  • Loading branch information
paca70 committed Apr 24, 2003
1 parent e40488f commit 1e22bc9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion lib/moodlelib.php
Expand Up @@ -489,7 +489,8 @@ function get_moodle_cookie() {
function create_user_record($username, $password) {
/// Creates a bare-bones user record
global $REMOTE_ADDR, $CFG;

//just in case check text case
$username = trim(moodle_strtolower($username));
if (function_exists(auth_get_userinfo)) {
if ($newinfo = auth_get_userinfo($username)) {
foreach ($newinfo as $key => $value){
Expand Down
2 changes: 1 addition & 1 deletion login/index.php
Expand Up @@ -21,8 +21,8 @@


if ($frm = data_submitted()) {
$frm->username = trim(moodle_strtolower($frm->username));
$user = authenticate_user_login($frm->username, $frm->password);

update_login_count();

if ($user) {
Expand Down
19 changes: 10 additions & 9 deletions login/signup.php
Expand Up @@ -6,7 +6,7 @@

if ($user = data_submitted()) {
validate_form($user, $err);

$user->username= trim(moodle_strtolower($user->username));
if (count((array)$err) == 0) {
$plainpass = $user->password;
$user->password = md5($user->password);
Expand Down Expand Up @@ -74,16 +74,17 @@

function validate_form($user, &$err) {
global $CFG;
if (empty($user->username))
if (empty($user->username)){
$err->username = get_string("missingusername");

else if (record_exists("user", "username", $user->username))
$err->username = get_string("usernameexists");

else {
$string = eregi_replace("[^([:alnum:])]", "", $user->username);
if (strcmp($user->username, $string))
}else{
$user->username = trim(moodle_strtolower($user->username));
if (record_exists("user", "username", $user->username)){
$err->username = get_string("usernameexists");
}else {
$string = eregi_replace("[^([:alnum:])]", "", $user->username);
if (strcmp($user->username, $string))
$err->username = get_string("alphanumerical");
}
}

if (isset($CFG->auth_user_create) and $CFG->auth_user_create==1 and function_exists('auth_user_exists') ){
Expand Down
2 changes: 1 addition & 1 deletion user/edit.php
Expand Up @@ -45,7 +45,7 @@
if ($usernew = data_submitted()) {
$usernew->firstname = strip_tags($usernew->firstname);
$usernew->lastname = strip_tags($usernew->lastname);

$usernew->username = trim(moodle_strtolower($usernew->username));
if (empty($_FILES['imagefile'])) {
$_FILES['imagefile'] = NULL; // To avoid using uninitialised variable later
}
Expand Down

0 comments on commit 1e22bc9

Please sign in to comment.