MDL-16919 - Allow username to contain alphanumeric lowercase characters, underscore (_), hyphen (-), period (.) or at symbol (@)

This commit is contained in:
Rossiani Wijaya
2010-01-13 06:23:54 +00:00
parent 8c594bbb11
commit 07ed083e4e
17 changed files with 188 additions and 46 deletions
+16
View File
@@ -219,6 +219,10 @@ define('PARAM_THEME', 'theme');
*/
define('PARAM_URL', 'url');
/**
* PARAM_USERNAME - Clean username to only contains specified characters.
*/
define('PARAM_USERNAME', 'username');
///// DEPRECATED PARAM TYPES OR ALIASES - DO NOT USE FOR NEW CODE /////
@@ -463,6 +467,7 @@ function validate_param($param, $type, $allownull=false, $debuginfo='') {
* @uses PARAM_BASE64
* @uses PARAM_TAG
* @uses PARAM_SEQUENCE
* @uses PARAM_USERNAME
* @param mixed $param the variable we are cleaning
* @param int $type expected format of param after cleaning.
* @return mixed
@@ -722,6 +727,17 @@ function clean_param($param, $type) {
return ''; // Specified theme is not installed
}
case PARAM_USERNAME:
$param = str_replace(" " , "", $param);
if (empty($CFG->extendedusernamechars)) {
// regular expression, eliminate all chars EXCEPT:
// alphanum, dash (-), underscore (_), at sign (@) and period (.) characters.
$param = preg_replace('/[^-\.@_a-z0-9]/', '', $param);
} else {
$param = preg_replace('/[A-Z]/', '', $param);
}
return $param;
default: // throw error, switched parameters in optional_param or another serious problem
print_error("unknownparamtype", '', '', $type);
}