Author Topic: [MOD] Unexpected chars and lenght nickname on registration  (Read 6219 times)

0 Members and 1 Guest are viewing this topic.

Offline Aleksey

  • Newbie
  • *
  • Posts: 37
    • View Profile
By default, you can register a user's nickname with any length and characters. This is very bad, there is no filtering.

This mod is lost, but it is very important and I will post it again.
This is not my mod, I restored it from my gallery.

Description: this mod checks the nickname when registering a user for forbidden characters and the length of the nickname.
By default, this mod allows the length of nicknames from 2 to 25 characters. As well as only English and Russian letters, numbers, space. But you can change that.

This MOD works on 4images 1.8 and PHP 7.4.4

[ Changed Files ]
includes/constants.php
register.php
templates/register_form.html
lang/<your language>/main.php

[ Installation ]

First Backup your Files

Step 1
Open register.php

Find
Code: [Select]
  $captcha = (isset($HTTP_POST_VARS['captcha'])) ? un_htmlspecialchars(trim($HTTP_POST_VARS['captcha'])) : "";

  $error = 0;
below insert
Code: [Select]
//Mod UNEXPECTED CHARS START
function comprobar_username($nombre_usuario){

$long_max = MAX_USER_KEYWORD_LENGTH;
$long_min = MIN_USER_KEYWORD_LENGTH;
$sag = '';
if (strlen($nombre_usuario)<$long_min){
$sag = 2; // devuelve 2, como diciendo "error 2"
return $sag;
}
if (strlen($nombre_usuario)>$long_max){
$sag = 3; // devuelve 3, como diciendo "error 3"
return $sag;
}

$permitidos = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzЙЦУКЕЁНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮйцукеёнгшщзхъфывапролджэячсмитьбю0123456789 ";

for ($i=0; $i<strlen($nombre_usuario); $i++){
if (strpos($permitidos, substr($nombre_usuario,$i,1))===false){
$sag = $sag.substr($nombre_usuario,$i,1);
}
}
if ($sag != ''){
return $sag;
}
return true;
  }
//Mod UNEXPECTED CHARS END

You can change this string and enter your allowed characters.
$permitidos = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzЙЦУКЕЁНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮйцукеёнгшщзхъфывапролджэячсмитьбю0123456789 ";

Find
Code: [Select]
        $msg .= (($msg != "") ? "<br />" : "").$lang['username_exists'];
        $error = 1;
      }
below insert
Code: [Select]
//Mod UNEXPECTED CHARS START
elseif (comprobar_username($user_name) != 1)
      {
$long_car = '';
for ($i=0; $i<strlen(comprobar_username($user_name)); $i++){
$long_car = $long_car.'#';
}

$resultado_func = comprobar_username($user_name);

if(strlen($resultado_func) >= 1 and $resultado_func != 2 and $resultado_func != 3){
$msg .= (($msg != "") ? "<br />" : "").$lang['username_bad_characters'];
$msg .= ": ".$resultado_func;
}
if($resultado_func == 2){
$msg .= (($msg != "") ? "<br />" : ""). $lang['user_name_short'];
}
if($resultado_func == 3){
$msg .= (($msg != "") ? "<br />" : ""). $lang['user_name_long'];
}

$recom = strtolower($user_name);
$recom = strtr($recom, " ", "_");
$recom = strtr($recom,comprobar_username($user_name), $long_car);
for ($i=0; $i<strlen($recom); $i++){
if (strpos($recom,'#')=== false){
}else{
$recom = substr($recom, 0,strpos($recom,'#')).substr($recom, strpos($recom,'#')+1);
}
}

$recom = trim($recom);

$long_max = MAX_USER_KEYWORD_LENGTH;
$recom = substr($recom,0,$long_max);

$username_option = $lang['user_name_option'].$recom;
 
        $error = 1;
      }

//Mod UNEXPECTED CHARS END

Step 2
Open templates/register_form.html

Find
Code: [Select]
<input type="text" name="user_name" size="30" value="{user_name}" class="input" />
below insert
Code: [Select]
<br>Allowed characters: A-Z a-z А-Я а-я 0-9 space<br>Nickname length: minimum 2, maximum 25 characters.

Step 3

Open includes/constants.php
Find
Code: [Select]
?>above insert
Code: [Select]
//Mod UNEXPECTED CHARS AND LENGHT NICKNAME
define('MIN_USER_KEYWORD_LENGTH', 2);
define('MAX_USER_KEYWORD_LENGTH', 25);
(these values are the minimum and maximum length of the nickname, edit as you need.)

Step 4

Open templates/main.php
Find
Code: [Select]
?>above insert
Code: [Select]
//Mod UNEXPECTED CHARS AND LENGHT NICKNAME
$lang['user_name_short'] = "The entered nickname is too short. The minimum value is 2 characters.";
$lang['user_name_long'] = "The entered nickname is too long. The maximum value is 25 characters.";
$lang['username_bad_characters'] = "Nickname contains invalid characters";
« Last Edit: May 08, 2020, 02:12:49 AM by Aleksey »