ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Maximum Username Length

June 28, 2007 9:12am

Subscribe [5]
  • #1 / Jun 28, 2007 9:12am

    bingomaster

    9 posts

    hello there

    can anyone tell me how I’d go about increasing the maximum username length for registering members?

    our client is using email addresses as usernames and one person has an email address of 50 characters long

    I’ve never heard of anyone having that lenght email address before, but there you go, I bet it’s easy to remember 😊

    I’m guessing I need to edit the max length of a particular field in a particular table, but don’t know which table.

    Any help, greatly appreciated.

  • #2 / Jun 28, 2007 10:06am

    Robin Sowell

    13255 posts

    I’ve never done it before- but took a look.  The db field looks ok- will go up to 50:

    `username` varchar(50) NOT NULL default '',

    I know to actually validate, you’ll need to alter system/core/core.validate.php around line 142- there’s a hard coded limit there:

    /** ----------------------------------
            /**  Is username max length correct?
            /** ----------------------------------*/
    
            if (strlen($this->username) > 32)
            {
                $this->errors[] = $LANG->line('username_password_too_long');
            }

    And you’ll need to make sure that any form fields are long enough to allow that many characters.  Untested- but looks like that should do the trick if they really need it to be more than 32 characters.

  • #3 / Jun 28, 2007 10:55am

    bingomaster

    9 posts

    Robin, you’re a star

    I wish to god we didn’t have to do it, it’s ludicrous having an email address that long.

    Which table is the field username in Robin?

    sorry to be a dumbass

  • #4 / Jun 28, 2007 11:02am

    bingomaster

    9 posts

    I got it, exp_members

  • #5 / Jun 28, 2007 11:43am

    Robin Sowell

    13255 posts

    Heh- sorry, just got caught up on old posts and heading back to the new ones.  Glad you spotted it!  (And yea- that’s pretty long for a username- but I’ve had clients come up with stuff way more insane than that.  I am now far more familiar with the validation class than I’d like to be!)

  • #6 / Jun 28, 2007 11:43am

    bingomaster

    9 posts

    I’ve edited the validate.php file,altered the database username field to accept 100 characters, and now I’m in the process of altering the forms.

    I’ve changed the registration form in CP Home ›  Admin ›  Members and Groups ›  Member Profile Templates ›  Default

    Cleared the cache, restarted apache.

    I’m still only able to add 32 characters in the register new members page in the admin backend.

    Am I editing the correct form Robin?

    Which form would I need to edit to expand this username field for members logging in as well from the font entd?  I can’t seem to find another form that looks relevant in that section.

    Thanks for helping Robin, I always appreciate it.

  • #7 / Jun 28, 2007 11:49am

    Robin Sowell

    13255 posts

    Ah- the backend control panel member area?  Is handled by system/cp files- in the case of registering a new member through the backend, it’s handled by system/cp/cp.member.php- the new_member_profile_form() function.  Around line 2493, it looks like:

    $r .= $DSP->itemgroup(
                                    $DSP->required().NBS.$LANG->line('username', 'username'),
                                    $DSP->input_text('username', '', '35', '32', 'input', '300px')

    You can always do a reveal code- look at the rendered code for the form in question.  Make sure it’s not the form field setting that’s cutting it off.  I suspect it is if you’re doing it in the backend.

    Frontend is handled by the module- backend display by the cp files (cp= control panel).

  • #8 / Jun 28, 2007 12:11pm

    bingomaster

    9 posts

    Thanks Robin, that did the trick and I’ve changed the from in the members section so we can now add 100 characters into the username if needed.

    I’m sure we’ll have some other forms that need changing to accomodate this but I’ll so them as and when they come up.

    one point is that the email field is set to 50 anyway, so if they have an email address of longer than that then we’ll have to change that too

    I hope not

    Do you know of any good reason I can turn around to the client and say that this is stupid, if you have users with that long email addresses they can’t join with that email address, and we’ll create a gmail account for them?

    You don’t know of any techinical reason apart from this whole request for help?  😉

  • #9 / Jun 28, 2007 12:34pm

    Robin Sowell

    13255 posts

    Hm- tough one.  I generally discourage anything that requires a hack- because they make updates a real pain.  Every upgrade, you’ll need to go in and change it.  And a username that long is really not necessary.  But the email thing…  I’m not keep on telling someone they have to change their email, either.  It’s not user friendly.  (Though +50 characters is a dang long email addy.)  Still- I think they aren’t being unreasonable in that regard- if their members really have email addresses that long. 

    Blarg- I think I’d put in a FR to allow for a longer email address if it’s a real issue.  And I think I’d discourage them from using a longer username- tell them it may have unintended consequences (true) and will add considerably to the time required for maintaining it.  And then I’d make sure to charge by the hour if they insist on it.  Heh.

    But yep- changes to membership like that- you have to hit the module, the validation class, and the backend cp, and the member templates.  It’s not fun stuff to hack.

  • #10 / Oct 21, 2007 2:25pm

    dmacli

    141 posts

    On a related note, what would be the best way to limit the length of the screen name of a user.  People have recently been doing this:

    **xxxxxTHE-AWESOMELY-LONG_SCREENNAMExxxxx**

    Its quite annoying because it breaks the formatting of my page!

  • #11 / Oct 22, 2007 12:53pm

    Robin Sowell

    13255 posts

    It doesn’t look like there’s a length check in the validator so it would be constrained by the db field size and the form field setting- so you could just edit the max characters allowed in the form field- just edit the templates.  It’s what I’d do in this particular case.  Make sense?

  • #12 / Oct 22, 2007 4:04pm

    dmacli

    141 posts

    Yep I did it and it worked!  There are 2 member templates that need editing.  Many thanks!

  • #13 / Oct 16, 2008 11:52am

    Emily Heath

    197 posts

    Hi, I’ve just stumbled upon this problem too. A user has an email address that is 33 characters long, which is being rejected as the username.  I can’t believe more people haven’t had this problem - is it because other developers don’t use the email address as username very often?
    Is there really no other way to get around it that hacking all those files? :(

  • #14 / Oct 16, 2008 12:12pm

    Robin Sowell

    13255 posts

    I suspect it’s because using the email as the username is rare. 

    I just took a look at the latest files, and they do still limit it to 32 characters.  See core.validate.php:

    (strlen($this->username) > 32)

    You may not need to change both front and backend- depending on how things will be used.  But at the moment, you’ll either need to hack- or perhaps write an extension.  I think my preference would be to discourage using the email as the username.

  • #15 / Oct 16, 2008 1:45pm

    Emily Heath

    197 posts

    Thanks for looking into this again Robin.

    I like email as username because I’m forever forgetting usernames for all the various sites I’m registered on (its hard enough remembering the password) and I imagine this is the same for other users.

    I wish I had the skills to write an extension for fixing this, but I don’t!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases