New Problem With name checking...

Started by {Makenzi}, February 22, 2019, 06:29:33 PM

Previous topic - Next topic

{Makenzi}

I modified register.php to check is username is valid and here is my problem: It allows registration even if there is ! near username ( invalid username )...
Here is check
This number != 1 was != 0 but it won't work with != so this green check works but it allows invalid name (Example name "Name" is not valid and it says its not valid but it registers user... )
if (preg_match('/^([A-Z]{1,1})[a-z]{2,9}+_([A-Z]{1,1})[a-z]{2,9}$/', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $context['checked_username'])) != 1 || $context['checked_username'] == '_' || $context['checked_username'] == '|' || strpos($context['checked_username'], '[code') !== false || strpos($context['checked_username'], '[/code') !== false)
$context['valid_username'] = false;

{Makenzi}

Sorry because of bump, but now i get everything to work except one thing, here is my whole code, sorry for double post... I do not know forum rules, I'll read them after i get help cuz this is very important...

function RegisterCheckUsername()
{
global $sourcedir, $smcFunc, $context, $txt;

// This is XML!
loadTemplate('Xml');
$context['sub_template'] = 'check_username';
$context['checked_username'] = isset($_GET['username']) ? $_GET['username'] : '';
$context['valid_username'] = true;

// Clean it up like mother would.
$context['checked_username'] = preg_replace('~[\t\n\r \x0B\0' . ($context['utf8'] ? ($context['server']['complex_preg_chars'] ? '\x{A0}\x{AD}\x{2000}-\x{200F}\x{201F}\x{202F}\x{3000}\x{FEFF}' : "\xC2\xA0\xC2\xAD\xE2\x80\x80-\xE2\x80\x8F\xE2\x80\x9F\xE2\x80\xAF\xE2\x80\x9F\xE3\x80\x80\xEF\xBB\xBF") : '\x00-\x08\x0B\x0C\x0E-\x19\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $context['checked_username']);
if ($smcFunc['strlen']($context['checked_username']) > 25)
$context['checked_username'] = $smcFunc['htmltrim']($smcFunc['substr']($context['checked_username'], 0, 25));

// Only these characters are permitted.

if(!IsValidName($_GET['username'])) //This
    $context['valid_username'] = false;

if (preg_match('~[<>&"\'=\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $context['checked_username'])) != 0 || $context['checked_username'] == '_' || $context['checked_username'] == '|' || strpos($context['checked_username'], '[code') !== false || strpos($context['checked_username'], '[/code') !== false)
$context['valid_username'] = false;

if (stristr($context['checked_username'], $txt['guest_title']) !== false)
$context['valid_username'] = false;

if (trim($context['checked_username']) == '')
$context['valid_username'] = false;
else
{
require_once($sourcedir . '/Subs-Members.php');
$context['valid_username'] &= isReservedName($context['checked_username'], 0, false, false) ? 0 : 1;
}
}

function IsValidName($name) //This
{
    return preg_match("/^[A-Z]{1}[A-Za-z]+_[A-Z]{1}[A-Za-z]+$/", $name);
}

//This - New code i added...
Problem is this:

Even if I see that symbol, it allows me to register when i click register button...

live627

Your code may need to be duplicated into Register2().

Advertisement: