By sisyphus on
I would want to disallow users register with user name having space or non-alphanumeric characters (2 bytes character. e.g Chinese characters). I think i have to hack the code of users.module. anyone could advise me or having any experience?
thanks a lot .
Comments
access rules is there
There is an admin setting for access rules
[localhost]/admin/user/rules/add
thank you. i studied the
thank you.
i studied the access rules screen but i do not understand these two fields:
%: Matches any number of characters, even zero characters.
_: Matches exactly one character.
how to set the values to accomplish my requirement?
thanks a lot.
If you want to disallow space
If you want to disallow space in the username
Access type: Deny
Rule type: Username
Mask: % %
See there is space between two '%'
Here % means any number of characters
- Another case If you don't want user to register with single character then you can put the Mask as
Access type: Deny
Rule type: Username
Mask: _
- Another case If you don't want user to register with two characters then you can put the Mask as
Access type: Deny
Rule type: Username
Mask: __
Thank you very much. Now the
Thank you very much.
Now the requirement of disallowing users to use username with space is solved.
And I would like to disallow users to use non-alphanumeric characters (e.g. Japanese, Chinese.... ) in username too.
I saw these codes in users.module:
What codes should be added to this list to disallow non-alphanumeric characters to form the username?
Thanks a lot.
Perhaps Regular Expressions?
This is a great thread, and I agree that this might need to be expanded a bit to get tighter control over valid characters/strings. Perhaps this module deserves a bit of a regular expressions upgrade, with several example rules for the common user. Just a thought.
The main motivation I would have for such tight control is integrating with other systems that would use the same or similar login credentials.
__________
Regards,
Chad Hester
% % is not working. I can
% % is not working. I can still register a username containing spaces.
Did you check it ?
It worked when I created a
It worked when I created a seperate rule for it. Don't join it with other rules.
i would like to disallow
i would like to disallow usernames with admin in them eg. admin1
how can i do that without blocking admin
add these rules disallow
add these rules
disallow username %admin%
allow username admin
Is there a way to deny all,
Is there a way to deny all, and only allow the following characters?
[a-z][A-Z][0-9]_
People are registering on a public site and specifying their email as the username, which of course will be splattered with spam. Then there's passing usernames in URL to views... and if you want to dynamically add usernames to a view filter with AND/OR +/- syntax, that might break things as well...
I would really like to avoid all confusion and only allow alphanumeric and underscore characters.
Best,
Andrey.
You can disallow the use of
You can disallow the use of "@" in usernames.
SUBSCRIBE to this:
SUBSCRIBE to this: [a-z][A-Z][0-9]_
how to disable all accents and special characters in username ?
OK, its easy: find a function
OK, its easy:
in user.module find a line:
function user_validate_name($name) {
and add this below this line:
What it does for Username:
- use only a-z A-Z 0-9 and - (dash)
- no accents like: ç , ą , ę , etc...
- no spaces
- no - (dash) in the beginnig or in the end of username
- minimum length of username is 5 characters
After that I removed all access rules in my drupal setup. This is quicker and nicer and has more options. The only problem, you need to hack user.module , so remember to make a copy of that file and provide those changes after every drupal core update.
I dont know how to create a custom module with those options, if anybody has the idea, would be great.
Enjoy clean and easy usernames on your site ;)
Thanks benone! I actually
Thanks benone! I actually just added the code and it worked perfectly!
One question I do have (for everyone) - what do you do about users who already have a username in place that has special characters or spaces? Can they still login? Also, I can send an email to all of the users asking them to update their username (if applicable), but it is doubtful that many will do this. Any ideas?
yeah, thats a good
yeah, thats a good question.
i would change them by hand and email each about new username.
but if you have more ... huh that might be hard..
follow-up
Just wanted you to know that users that have special characters in their usernames can still log-in, if they set-up their account before this code is added. All new users have to follow the special character rules when setting up their accounts. The old users are "grandfathered" in, so to speak.
I still haven't come up with a reasonable way to get the original users update their usernames, so for now I'm just ignoring that point. Thanks again for the useful code!
Thanks!
Thanks for this code, benone! This is something that should become standard in all drupal installed, it's really helped me a lot!
i also like to implement a
i also like to implement a white-list for the allowed characters in the username. hacking the user.module file works for me, but i'm wondering, if there is a better (more drupal) way than hacking the core.
did anyone try to alter the user-registration and user-edit form yet? (e.g. own element specific validation function for the username)
Yes i had tried with
Yes i had tried with hook_user
Hope this helps
Acquia certified Developer, Back end and Front specialist
Need help? Please use my contact form
This is exactly what I was looking for.
I don't know why drupal does not makes it easier to do. Here is what I want. Please help:
Only following should be allowed for username.
Minimum characters: 4
Maximum characters: 15
A - Z
a - z
0 - 9
. (period)
_ (underscore)
Should not start or end with . (period) and _ (underscore)
Should not start with numbers (o - 9)
Hi, Create a module which
Hi,
Create a module which will hook_user to validate the username. The function below will match your needs. Please check and confirm.
Regards
Sagar
Acquia certified Developer, Back end and Front specialist
Need help? Please use my contact form
Sagar, I really don't know
Sagar, I really don't know how to create a module. I have no knowledge in coding. Can you help me with that too?
Hi, here are the files you
Hi,
here are the files you need to have for above module :
username_validate.module file :
username_validate.info file :
you need place these files under sites/all/modules/username_validate directory.
Hope this helps.
Regards
Sagar
Acquia certified Developer, Back end and Front specialist
Need help? Please use my contact form
I created a module and
I created a module and uploaded in modules directory but I don't see it listed in admin/build/modules. So, I am not able to enable it. Please suggest how I can make it work.
Hi, My fault i missed one '}'
Hi,
My fault i missed one '}' in the .module file.
username_validate.module :
username_validate.info
place these files under yoursite/sites/all/modules/username_validate
Regards
Sagar
Acquia certified Developer, Back end and Front specialist
Need help? Please use my contact form
Its not working again. Please
Its not working again. Please check. I am using drupal 6.x.
Alternate way
It's not working for me too. I wrote alternate code with hook_form_alter.
Also, it would be helpful to
Also, it would be helpful to let the user know what they are allowed to use in their name before registering. Otherwise it will still say that Spaces are allowed, as well as other things. You can edit the username description with this variable $form['account']['name']['#description']. Here's what my hook_alter function looks like.
Disallow user names with more than one number
I would like to disallow user names with more than one number. Most spambots seem to create user names with four or more numbers in them, so this would take care of the vast majority of those registrations. (I have a captcha, Mollom, Spambot and Bad Behavior, but I still get 20-30 spam registrations a day)
Any idea how to implement this?
Great thread..
That is exactly I was looking for..thank you people..