News:

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

Main Menu

How can I limit username length?

Started by theserialcoder, March 06, 2012, 09:31:33 PM

Previous topic - Next topic

theserialcoder

By default I believe usernames can be only 25 characters. How can I modify this to only allow, for example, usernames to be at most 15 characters?

Thanks for your help.

kat

You don't say which version of SMF this is for... :(

If it's v2.0.2, and this is a pure guess. So, keep a copy of the file, as a backup, in case I've bolloxed it up, OK?

In the default theme's directory, find Register.template.php

It looks, to me, like the " maxlength="25", in the first line, is what you're after. Dunno what the size=30 thing does, though.

<input type="text" name="user" id="smf_autov_username" size="30" tabindex="', $context['tabindex']++, '" maxlength="25" value="', isset($context['username']) ? $context['username'] : '', '" class="input_text" />
<span id="smf_autov_username_div" style="display: none;">
<a id="smf_autov_username_link" href="#">
<img id="smf_autov_username_img" src="', $settings['images_url'], '/icons/field_check.gif" alt="*" />
</a>
</span>
</dd>
<dt><strong><label for="smf_autov_reserve1">', $txt['email'], ':</label></strong></dt>
<dd>
<input type="text" name="email" id="smf_autov_reserve1" size="30" tabindex="', $context['tabindex']++, '" value="', isset($context['email']) ? $context['email'] : '', '" class="input_text" />
</dd>
<dt><strong><label for="allow_email">', $txt['allow_user_email'], ':</label></strong></dt>
<dd>
<input type="checkbox" name="allow_email" id="allow_email" tabindex="', $context['tabindex']++, '" class="input_check" />
</dd>
</dl>';


theserialcoder

It is for v2.0.2, sorry about that. The size attribute for inputs just adjusts the width of the input field so the fact that it is 30 is fine. Maxlength would regulate the amount of input for the field on the client side but I'm more concerned with the server side validation. Someone can manipulate their client side code to allow them to input a longer name and I'd like to do a server side validation on the length of the username.

kat

To prove that this is way over my head, I have to confess that I have no idea what would control it, server-side.

I really thought that would've done the trick.

Let's hope that someone with a braincell sees this and can help you out. :)

IchBin™

IchBin™        TinyPortal

kat


Shambles


Illori

it is a thread in the charter board and for 1.1.1* as well.

that thread suggests looking in subs-members.php for the limit, it may have changed in 2.0 though.

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

IchBin™

IchBin™        TinyPortal

theserialcoder

Thanks for your help.

I also found these lines in Register.php that should be changed.
if ($smcFunc['strlen']($context['checked_username']) > 25)
$context['checked_username'] = $smcFunc['htmltrim']($smcFunc['substr']($context['checked_username'], 0, 25));


Now that the server side seems to have been handled I don't know where to actually change the client side form's maxlength. Anyone know what file contains the html for the registration form so I can change this line?

<input type="text" name="user" id="smf_autov_username" size="30" tabindex="', $context['tabindex']++, '" maxlength="25" value="', isset($context['username']) ? $context['username'] : '', '" class="input_text" />

Aleksi "Lex" Kilpinen

I would think the layout is done in Themes/default/register.template.php
Slava
Ukraini!


"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

theserialcoder

I overlooked the filename in K@'s original post. Thanks again!

Aleksi "Lex" Kilpinen

No problem :) Are we ready to mark this solved, or do you still need help with this?
Slava
Ukraini!


"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Advertisement: