Python library to validate usernames suitable for use in public facing applications.
Project description
python-usernames
Python library to validate usernames suitable for use in public facing applications where use can choose login names and sub-domains.
Features
- Provides a default regex validator
- Validates against list of banned words that should not be used as username.
- Python 3.8+
Installation
pip install python-usernames
Usages
from python_usernames import is_safe_username
>>> is_safe_username("jerk")
False # contains one of the banned words
>>> is_safe_username("handsome!")
False # contains non-url friendly `!`
is_safe_username takes the following optional arguments:
-
whitelist
: a case insensitive list of words that should be considered as always safe. Default:[]
-
blacklist
: a case insensitive list of words that should be considered as unsafe. Default:[]
-
max_length
: specify the maximun character a username can have. Default:None
-
regex
: regular expression string that must pass before the banned : words is checked.
The default regular expression is as follows:
^ # beginning of string
(?!_$) # no only _
(?![-.]) # no - or . at the beginning
(?!.*[_.-]{2}) # no __ or _. or ._ or .. or -- inside
[a-zA-Z0-9_.-]+ # allowed characters, atleast one must be present
(?<![.-]) # no - or . at the end
$ # end of string
Further Reading
Gotchas
Words like bigcock12
will validated just fine, only equality against
the banned word
lists
is checked. We don't try to be smart to avoid Scunthorpe
problem. If you can
come up with a algorithm/solution, please create an issue/pr :).
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python_usernames-1.0.0.tar.gz
.
File metadata
- Download URL: python_usernames-1.0.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82c68b9dccb6d0571eded31fe47b91ebca4b25e530a8703e8c06ebd9198f3f4f |
|
MD5 | c5a8f98aaf89254491f288c7e96fd7d8 |
|
BLAKE2b-256 | e40daad0e8609ad208f3972d9032266f452e04ef9919f8db7f9dab06f49782c7 |
File details
Details for the file python_usernames-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: python_usernames-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59fd41670d8ee550f93be1db25fb0112591b0566c44069d6d42ad26a5c71b474 |
|
MD5 | 64ac70942f76381c0e46d4b1167631fb |
|
BLAKE2b-256 | 5f4fd0f708985dceefcb8e9cb1eefe2b5f3d88b624ec927bb85fa69f89de8f50 |