News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Members username

Started by qICEp, July 29, 2013, 08:18:03 PM

Previous topic - Next topic

qICEp

Hi i have connected my SMF board to game server (Long time ago)
Registration and login are working both ways (From game server and smf)

Now i need to accept only certain format for username's  ( First_Middle_Last, First_Last, First_DeLast, ect) I have made regex for these in game but now i need it for SMF

I know i have to edit subs-members.php and im 100% sure these is the place.But im not sure what all of these regex functions do...so if someone can explain me as im not that good with regex (Please do not say what is already in comments, i know how to read, trust me)

// Spaces and other odd characters are evil...
$regOptions['username'] = preg_replace('~[\t\n\r\x0B\0' . ($context['utf8'] ? ($context['server']['complex_preg_chars'] ? '\x{A0}' : "\xC2\xA0") : '\xA0') . ']+~' . ($context['utf8'] ? 'u' : ''), ' ', $regOptions['username']);

// Don't use too long a name.
if ($smcFunc['strlen']($regOptions['username']) > 25)
$reg_errors[] = array('lang', 'error_long_name');

// Only these characters are permitted.
if (preg_match('~[<>&"\'=\\\\]~', preg_replace('~&#(?:\\d{1,7}|x[0-9a-fA-F]{1,6});~', '', $regOptions['username'])) != 0 || $regOptions['username'] == '_' || $regOptions['username'] == '|' || strpos($regOptions['username'], '[code') !== false || strpos($regOptions['username'], '[/code') !== false)
$reg_errors[] = array('lang', 'error_invalid_characters_username');

if ($smcFunc['strtolower']($regOptions['username']) === $smcFunc['strtolower']($txt['guest_title']))
$reg_errors[] = array('lang', 'username_reserved', 'general', array($txt['guest_title']));

// !!! Separate the sprintf?
if (empty($regOptions['email']) || preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $regOptions['email']) === 0 || strlen($regOptions['email']) > 255)
$reg_errors[] = array('done', sprintf($txt['valid_email_needed'], $smcFunc['htmlspecialchars']($regOptions['username'])));


First two check i figured out at first glance but the third one is a f****** rocket science for me even if its say these are characters that are allowed (permitted)
I need only A-Z upper and lover case, and _ not a single character more...not even numbers, so if you could explain or edit these regex,you would save my day.

I think im gonna need to edit the third check (regex) and add one more for my username format to work but im sux with regex and i have no idea what the third one does and how to remove all allowed characters but leave A-Za-z and _

Thx for any help

Branko.

Strong people don't put others down, they lift them up.
A clever person solves a problem. A wise person avoids it.

Advertisement: