restrictions for username selection
-
is it possible to restrict username selection for new users easily?
let's say someone is registering as
Michael
, then nodebb assignsMichael 0
,Michael 1
,Michael 2
etc. to the following users with the same name...But, I prefer if NodeBB asks (forces) them to pick another username, so each person will have more unique usernames...
Additionally, I think there should be a restriction to pick usernames with numbers only, such as "11111"... In the real world, no one has numerical names except Elon Musk's son "X Æ A-12 Musk". So, it would be better if more people are selecting more natural usernames...
Of course, I understand, people will always find another way... But for example, I would be ok with someone picking "Michael1980", but I am just trying to limit the number of "unwanted" usernames.
Is there any easy way to implement these restrictions?
-
I think the easiest solution is to use
filter:register.check
and throw an error if the username exists already or if it is invalid (like only numbers).So a plugin that only listens to that hook like this.
myPlugin.filterRegisterCheck = async (hookData) { // dont allow username 0,1,2,3 const exists = await meta.userOrGroupExists(hookData.username); if (exists) { throw new Error('[[error:username-taken]]'); } // add your own checks & rules if you want if (hookData.userData.username.startsWith('_')) { throw new Error('[[error:invalid-username]]'); } return hookData; };
The above would show an error if the username is already taken and prevent any usernames that start with
_
you can extend it to add more rules like preventing all number usernames. -