diff --git a/htdocs/auth/internal/lib.php b/htdocs/auth/internal/lib.php index 23543dcd7bab9bd94533bf81bac011cab380abba..523483bae02629aab08b883f324490c9333e89a2 100644 --- a/htdocs/auth/internal/lib.php +++ b/htdocs/auth/internal/lib.php @@ -132,6 +132,26 @@ class AuthInternal extends Auth { public function is_username_valid($username) { return preg_match('/^[a-zA-Z0-9!@#$%^&*()\-_=+\[{\]}\\|;:\'",<\.>\/?`]{3,30}$/', $username); } + /** + + + * Internal authentication allows most standard us-keyboard-typable characters + * for username, as long as the username is between three and 236 + * characters in length. + * + * This method is NOT part of the authentication API. Other authentication + * methods never have to do anything regarding usernames being validated on + * the Mahara side, so they do not need this method. + * + * This method is meant to only be called for validation by an admin of the user + * and is able to set a password longer than thirty characters in length + * + * @param string $username The username to check + * @return bool Whether the username is valid + */ + public function is_username_valid_admin($username) { + return preg_match('/^[a-zA-Z0-9!@#$%^&*()\-_=+\[{\]}\\|;:\'",<\.>\/?`]{3,236}$/', $username); + } /** * Changes the user's username. @@ -144,10 +164,19 @@ class AuthInternal extends Auth { * @return string The new username, or the original username if it could not be set */ public function change_username(User $user, $username) { + global $USER; + $this->must_be_ready(); // proposed username must pass validation - if ($this->is_username_valid($username)) { + $valid = false; + if ($USER->is_admin_for_user($user)) { + $valid = $this->is_username_valid_admin($username); + } else { + $valid = $this->is_username_valid($username); + } + + if ($valid) { $user->username = $username; $user->commit(); } diff --git a/htdocs/lib/db/install.xml b/htdocs/lib/db/install.xml index 28ae58acce389226f177a35f99f381248f94dc8b..9f304d88e52705897b537f41a0187ebf1de4c074 100644 --- a/htdocs/lib/db/install.xml +++ b/htdocs/lib/db/install.xml @@ -76,7 +76,7 @@ - + diff --git a/htdocs/lib/db/upgrade.php b/htdocs/lib/db/upgrade.php index 1a51430bd9a8da31b3204de8997ff3f3766eb0e0..744ef8f901e84f9231cb4c783cc33b437770a30b 100644 --- a/htdocs/lib/db/upgrade.php +++ b/htdocs/lib/db/upgrade.php @@ -2262,5 +2262,12 @@ function xmldb_core_upgrade($oldversion=0) { } } + if ($oldversion < 2011050600) { + $table = new XMLDBTable('usr'); + $field = new XMLDBField('username'); + $field->setAttributes(XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL); + change_field_precision($table, $field); + } + return $status; } diff --git a/htdocs/lib/version.php b/htdocs/lib/version.php index 1a88032678c2d652bfea81a3fe43e50a7a444f04..2822b1375da7fdc1c1b81bbbd28b186188fcb7e0 100644 --- a/htdocs/lib/version.php +++ b/htdocs/lib/version.php @@ -28,7 +28,7 @@ defined('INTERNAL') || die(); $config = new StdClass; -$config->version = 2011050300; +$config->version = 2011050600; $config->release = '1.4.0alpha2dev'; $config->minupgradefrom = 2008040200; $config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';