PDA

View Full Version : Warn users if username is too long!


Joshua Clinard
05-19-2002, 02:25 AM
Can someone create a hack that would warn users that their username is too long, instead of just registering them with the first (insert allowed number of characters here) characters, and cutting off the rest of the name.

This is a design flaw, in my opionion.

Logician
05-19-2002, 11:27 AM
In register.php find:

if (strlen($username)<$minuserlength) {

before that add:

if (strlen($username)>XX) {
eval("standarderror(\"".gettemplate("error_toolongusername")."\");");exit;
}

(Replace XX with max. char.number)

Login Admin CP/Create a New Template named error_toolongusername

Specify the text as you like (eg. "You user name is too long! Please go back and shorten it.")

Regards,

Admin
05-19-2002, 11:30 AM
Err, it already works like that.

Register.php:
if (strlen($username)<$minuserlength) {
eval("standarderror(\"".gettemplate("error_usernametooshort")."\");");
exit;
} elseif (strlen($username)>$maxuserlength) {
eval("standarderror(\"".gettemplate("error_usernametoolong")."\");");
exit;
}

Joshua Clinard
05-19-2002, 04:44 PM
I registered at one board with the username of Joshua Clinard, and when I got my confirmation e-mail, my username was Joshua Clin. Obviosly the max length was 10 characters, as the last 3 characters got cut off. I have had several users on my forums with names that appeared to be cut off as well, so if it is supposed to warn users that their username is too long, then that feature does not work.

I guess I'll have to submit a bug report, which I was going to do anyways, because this is a design flaw in my opionion.

Admin
05-19-2002, 04:47 PM
Perhaps the forum you registered at hacked their board. And unless users on your board tried to register with a 50-chars username, this should not and will not happen.

And if you look at Logician's post and mine, you will see that both code snippets pretty much do the same thing.

FWC
05-19-2002, 05:01 PM
Originally posted by FireFly
Perhaps the forum you registered at hacked their board. And unless users on your board tried to register with a 50-chars username, this should not and will not happen.Yep, this works fine on my board and another I help admin. Of course, I am very careful when applying hacks. :)

N!ck
05-19-2002, 09:55 PM
you could use a javascript, like this in the head:


<script language="JavaScript">
function unlength (form) {
if (form.blah.length > 15) {
alert("Your username is too long!");
form.blah.focus();
}
}
</script>


and then


<input type="text" name="blah" onBlur="unlength(this.form)">



of course, i'm no expert @ javascript; this COULD have an error

Joshua Clinard
05-20-2002, 04:20 PM
Well, I was wrong. I just tested this on a few forums and it does not let you type in more than the allowed number of characters. I wonder if this might be a browser incompatibility issue!

Admin
05-20-2002, 04:24 PM
No it's not, even if the user can type more than X characters, the PHP script will exit with an error message.

Logician
05-20-2002, 04:44 PM
Originally posted by Joshua Clinard
Well, I was wrong. I just tested this on a few forums and it does not let you type in more than the allowed number of characters. I wonder if this might be a browser incompatibility issue!
Joshua, maybe it's a better idea to apply the hack into YOUR board first, instead of trying to register boards which we dont know if they applied this or any others hack.

This hack will not let your users register with longer usernames than you allowed. So please try it and lets see if it works or not..

What Firefly said is true: This is a "server-side" check, so is not related to browser issues (unlike nicksaunders code).. Thus your users cant pass it.

Regards,

Admin
05-20-2002, 04:46 PM
Logician: There is no need to apply your hack, like I said this check is already built into vBulletin (or the option wouldn't be in the Admin CP). :)

Logician
05-20-2002, 05:25 PM
it is there indeed.. How come did I miss it when writing the hack? lol

Joshua Clinard
05-20-2002, 06:55 PM
Thanks Chen!