Camen Design Forum

Stop users from registering spaces in their usernames

append delete dummy

Hi @Kroc and @Martijn.

I just start learn PHP from scratch. Now I make progress to link source code to MySql database and sent data to database.

I want to know how to prevent users from registering spaces in their usernames?

Reply RSS

Replies

append delete #1. Martijn

The username is used a little bit everywhere, due to the way it is setup. What is actually done is a sha512 hash is created from the provided name and that is used further on.

If you look for `create the user` in the source code (default lines 193 to 198 in start.php):

%
        //create the user, if new:
        //- if registrations are allowed (`FORUM_NEWBIES` is true)
        //- you can’t create new users with the HTTP_AUTH sign in
        if (FORUM_NEWBIES && !isset ($_SERVER['PHP_AUTH_USER']) && !file_exists ($user))
                file_put_contents ($user, hash ('sha512', $name.PASS)) or require FORUM_LIB.'error_permissions.php'
        ;
%

This is where a new user will be stored on the server, by creating a file that has the sha512 hash of the user name as the filename.

I would think about expanding that `if` clause to do additional checks would allow you to introduce new limitations to usernames. E.g. add something like `strpbrk(NAME, " ") === false`. (strpbrk will return false when none of the provided characters are found, we only want to continue if spaces are not found to we need to compare with false.)

You can easily add other symbols you do not want to allow then, like maybe you want to block things that look like web addresses or email addresses: `strpbrk(NAME, " @:") === false`

I am not sure how to best communicate this error to the user though. It would just look like something randomly failed?

append delete #2. dummy

@Martijn "I am not sure how to best communicate this error to the user though. It would just look like something randomly failed?"

I just thinking.

After add the code.

`strpbrk(NAME, " ") === false`.

Maybe I need tu change the Name field : Your Name to Your Name (without space).

And without give error to the user. So I don't need to put

echo "error" / "Your Name (without space)"

Reply

(Leave this as-is, it’s a trap!)

There is no need to “register”, just enter the same name + password of your choice every time.

Pro tip: Use markup to add links, quotes and more.

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn