Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

I want to stop users from being able to use usernames with spaces

Pls, I want to stop users from being able to use usernames with spaces in it, please can somebody help me with how to go about this? I am running vanilla 2.2

Comments

  • depends what characters you will allow.

    $Configuration['Garden']['User']['ValidationRegex'] = '[A-Za-z0-9\-_]';

    Allows alphanumeric plus underscore an dash but no spaces.

    You can adjust the length

    $Configuration['Garden']['User']['ValidationLength'] = '{3,15}';

    The first number is minimum and the second number is maxoum

    grep is your friend.

  • Sorry I didn't mention the spaces in usernames only happens when users sign in with facebook, twitter or google plus. This solution doesn't seem to fix it. @x00

  • hgtonighthgtonight ∞ · New Moderator

    @xm1 said:
    Sorry I didn't mention the spaces in usernames only happens when users sign in with facebook, twitter or google plus. This solution doesn't seem to fix it. @x00

    The Facebook connect plugin passes the real names in as the username. Is there a specific reason you don't want spaces in those names?

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • @hgtonight the Facebook connect plugin does not pass the real names in my installation. It allows them to choose a username after connection.

    Here is why I don't want spaces.
    First, mentioning a username with a space doesn't work in my installation even though I add quotes like this @user name
    Apart from that I prefer usernames without spaces in them.

  • hgtonighthgtonight ∞ · New Moderator

    @xm1 said:
    @hgtonight the Facebook connect plugin does not pass the real names in my installation. It allows them to choose a username after connection.

    Here is why I don't want spaces.
    First, mentioning a username with a space doesn't work in my installation even though I add quotes like this @user name
    Apart from that I prefer usernames without spaces in them.

    You would have to modify the Facebook Connect plugin to validate the username or passing the username through a conforming function.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • @hgtonight said:
    You would have to modify the Facebook Connect plugin to validate the username.

    Could you please give me an idea on how to do this?

  • hgtonighthgtonight ∞ · New Moderator

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • @x00 said:
    depends what characters you will allow.

    $Configuration['Garden']['User']['ValidationRegex'] = '[A-Za-z0-9\-_]';

    Allows alphanumeric plus underscore an dash but no spaces.

    For other's benefit II made a mistake

    $Configuration['Garden']['User']['ValidationRegex'] = 'A-Za-z0-9\-_';

    is correct.

    grep is your friend.

  • xm1xm1 New
    edited January 2016

    @x00 said:
    For other's benefit ...

    This is how I solved my problem.
    I added the following code above the if statement @hgtonight highlighted (Not inside it, above it).

    `
    $chosenUsername = $Form->getValue("ConnectName");

        if (empty($Form->getValue("ConnectPassword"))) {
            $usr = Gdn::UserModel()->getWhere(array('Name' => $chosenUsername ))->firstRow(DATASET_TYPE_ARRAY);
            try {
                if (!empty($usr)) {
                    throw new Gdn_UserException("The username you entered already exists.");
                }
            } catch (Exception $ext) {
                $Form->addError($ext);
            }
        }
        if (!validateUsername($chosenUsername )) {
           $Form->addError('ValidateUsername', 'ConnectName');
        }`
    

    I also repeated the code in the twitter and googleplus plugins.
    While on it I discovered that the twitter plugin do not validate emails. I went through my registered users record and found that some users who signed in with twitter used one letter as their email.
    To solve this I added this in the twitter plugin.

    `
    $chosenEmail = $Form->getValue("Email");

        if (!validateEmail($chosenEmail)) {
            $Form->addError('ValidateEmail', 'Email');
        }`
    
Sign In or Register to comment.