How to control what is used for a username at signup

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

How to control what is used for a username at signup

Post by shasta59 » 2016-03-29 03:40

Using Appgini 5.50

Have you ever wanted to control what is used as a username when a new user creates an account? For example, if you wish to not allow 'Superman vs Batman' as a user name then just do the following:

Open inc.Function.php in the admin folder of your app.

Then look for function is_allowed_username($username){ - should be around line 662

Directly below $username = trim(strtolower($username));
Create a new line with the following:

Code: Select all

if(preg_match('/superman vs batman/i', $username)) return false;
(The “i” after the pattern delimiter indicates a case-insensitive search )

You can put in whatever you wish to prevent being used. In this case, once someone types in whatever you wish to prevent it will come up with a warning and not allow the username. If you wish to prevent, for example, an email address being used as a username put in the following:

Code: Select all

if(preg_match('/@/i', $username)) return false;
Be careful however as this will not allow the '@' symbol to be used which is used in all email addresses. It could be used elsewhere and then you have an issue. There is another way to prevent an email address from being used by checking if it is a valid email address then not allowing it. (More on how to do that in another post)

What I have also done is create a list of unacceptable usernames and put them in a text file. I then have a line of code which checks to see if any of the usernames typed in are in that list and if so not allow them to be used.

Enjoy

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

Post Reply