View Single Post
  #2  
Old 05-06-2017, 09:20 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 68,112
Dinocanid is on a distinguished road
Default

I'm not too sure on the date checking, but you should be able to prevent special characters in usernames by adding this under "protected function usernamevalidate" in class_registervalidator.php:
PHP Code:
if(preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/'$username)){

         
$this->seterror("Your username cannot contain special characters!");

         return 
FALSE;

      } 
So it looks like this:
PHP Code:
protected function usernamevalidate($username ""){
      
// The username validator, note its a bit complicate here due to the different mechanism of username check for register and other validators
      
$lang Registry::get("lang");
      if(!
$this->emptyvalidate($username)){
         
$this->seterror("The field Username is Empty.");
         return 
FALSE;
      }
      if(
$username == "SYSTEM"){
         
$this->seterror("Cannot use SYSTEM as username.");
         return 
FALSE;
      }
      if(
preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/'$username)){
         
$this->seterror("Your username cannot contain special characters!");
         return 
FALSE;
      }
      
$username = (empty($username))?$this->value['username']:$username;      
      
$userexist $this->datavalidate("users", array("username"), "username = '{$username}'");
      if(
$userexist == TRUE){
         
$this->seterror($lang->user);
         return 
FALSE;
      }
      else return 
TRUE;
  } 
I haven't tried it, but I got the answer from here:
http://stackoverflow.com/questions/3...characters-php

EDIT: Thought I should say that this won't/can't do anything about users who already registered with special characters; only new ones.
__________________

Last edited by Dinocanid; 05-06-2017 at 09:37 PM.
Reply With Quote