/** * Given a username, returns one of several codes to indicate whether it is valid to be a NEW username or not. * * Codes: * - OK: A user with this username may be created. * - INVALID: This is not a valid username. This may mean that it is too long or has characters that aren't permitted, etc. * - EXISTS: A user with this name, so you cannot create one with this name. * * TODO: Is this a duplicate of user::isCreatableName()? It is important to note that wgWikiaMaxNameChars may be less than wgMaxNameChars which * is intentional because there are some long usernames that were created when only wgMaxNameChars limited to 255 characters and we still want * those usernames to be valid (so that they can still login), but we just don't want NEW accounts to be created above the length of wgWikiaMaxNameChars. * * @param string $uName The user name to check * * @return bool|string Return errors as an i18n key or true if the name is valid */ function wfValidateUserName($uName) { if (!User::isNotMaxNameChars($uName)) { return 'userlogin-bad-username-length'; } $userTitle = Title::newFromText($uName); if (is_null($userTitle)) { return 'userlogin-bad-username-character'; } $uName = $userTitle->getText(); if (!User::isCreatableName($uName)) { return 'userlogin-bad-username-character'; } $dbr = wfGetDB(DB_SLAVE); $uName = $dbr->strencode($uName); if ($uName == '') { return 'userlogin-bad-username-character'; } if (class_exists('SpoofUser')) { $spoof = new SpoofUser($uName); if ($spoof->isLegal()) { $conflicts = $spoof->getConflicts(); if (!empty($conflicts)) { return 'userlogin-bad-username-taken'; } } } if (in_array($uName, F::app()->wg->ReservedUsernames)) { // if we returned 'invalid', that would be confusing once a user // checked and found that the name already met the naming requirements. return 'userlogin-bad-username-taken'; } // This username is valid return true; }
/** * Given a username, returns one of several codes to indicate whether it is valid to be a NEW username or not. * * Codes: * - OK: A user with this username may be created. * - INVALID: This is not a valid username. This may mean that it is too long or has characters that aren't permitted, etc. * - EXISTS: A user with this name, so you cannot create one with this name. * * TODO: Is this a duplicate of user::isCreatableName()? It is important to note that wgWikiaMaxNameChars may be less than wgMaxNameChars which * is intentional because there are some long usernames that were created when only wgMaxNameChars limited to 255 characters and we still want * those usernames to be valid (so that they can still login), but we just don't want NEW accounts to be created above the length of wgWikiaMaxNameChars. */ function wfValidateUserName($uName) { wfProfileIn(__METHOD__); $result = true; #wfMsg ('username-valid'); $nt = Title::newFromText($uName); if (!User::isNotMaxNameChars($uName)) { $result = 'userlogin-bad-username-length'; } elseif (is_null($nt)) { $result = 'userlogin-bad-username-character'; } else { $uName = $nt->getText(); if (!User::isCreatableName($uName)) { $result = 'userlogin-bad-username-character'; } else { $dbr = wfGetDB(DB_SLAVE); $uName = $dbr->strencode($uName); if ($uName == '') { $result = 'userlogin-bad-username-character'; } else { if (User::idFromName($uName) != 0) { $result = 'userlogin-bad-username-taken'; } global $wgReservedUsernames; if (in_array($uName, $wgReservedUsernames)) { $result = 'userlogin-bad-username-taken'; // if we returned 'invalid', that would be confusing once a user checked and found that the name already met the naming requirements. } } } } wfProfileOut(__METHOD__); return $result; }
/** * Validates username user enters on rename account form * * @author grunny */ private function validateUserName($userName) { global $wgWikiaMaxNameChars; if ($userName == '') { $this->err[] = $this->msg('userlogin-error-noname')->escaped(); $this->errInputs['wpUserNameNew'] = true; return false; } // check username length if (!User::isNotMaxNameChars($userName)) { $this->err[] = $this->msg('usersignup-error-username-length', $wgWikiaMaxNameChars)->escaped(); $this->errInputs['wpUserNameNew'] = true; return false; } // check valid username if (!User::isCreatableName($userName)) { $this->err[] = $this->msg('usersignup-error-symbols-in-username')->escaped(); $this->errInputs['wpUserNameNew'] = true; return false; } $result = wfValidateUserName($userName); if ($result === true) { $msgKey = ''; if (!wfRunHooks('cxValidateUserName', array($userName, &$msgKey))) { $result = $msgKey; } } if ($result !== true) { $msg = ''; if ($result === 'userlogin-bad-username-taken') { $msg = $this->msg('userlogin-error-userexists')->escaped(); } else { if ($result === 'userlogin-bad-username-character') { $msg = $this->msg('usersignup-error-symbols-in-username')->escaped(); } else { if ($result === 'userlogin-bad-username-length') { $msg = $this->msg('usersignup-error-username-length', $wgWikiaMaxNameChars)->escaped(); } } } $this->err[] = empty($msg) ? $result : $msg; $this->errInputs['wpUserNameNew'] = true; return false; } return true; }
public function initValidationPassword() { // check empty password if ($this->mPassword == '') { $this->mainLoginForm(wfMsg('userlogin-error-wrongpasswordempty'), 'error', 'password'); return false; } // check password length if (!User::isNotMaxNameChars($this->mPassword)) { $this->mainLoginForm(wfMsg('usersignup-error-password-length'), 'error', 'password'); return false; } return true; }