Skip to main content

Python library to validate usernames suitable for use in public facing applications.

Project description

Build Status Coverage Status PyPI version

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 2.7, 3.4, 3.5, 3.6, 3.7 pypi

Installation

pip install python-usernames

Usages

from 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:

  • regex: regular expression string that must pass before the banned words is checked.

  • whitelist: a list of words that should be considered as always safe.

  • blacklist: a list of words that should be considered as unsafe.

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

Note:

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-usernames-0.2.3.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

python_usernames-0.2.3-py2.py3-none-any.whl (7.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file python-usernames-0.2.3.tar.gz.

File metadata

  • Download URL: python-usernames-0.2.3.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/17.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.10

File hashes

Hashes for python-usernames-0.2.3.tar.gz
Algorithm Hash digest
SHA256 44348eb66d4455cd4d51f9d8dab8ce63ff25edc4803c5b8c78b7ffade97371a1
MD5 4c80d583a1f6d82fb5904daa9cc40b6f
BLAKE2b-256 6ec9977a6730d7b6f5954541c2804b28b3c1808d29c6d75ca1b4a96db8360960

See more details on using hashes here.

File details

Details for the file python_usernames-0.2.3-py2.py3-none-any.whl.

File metadata

  • Download URL: python_usernames-0.2.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/17.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/2.7.10

File hashes

Hashes for python_usernames-0.2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f78abf5260911e371cbf6a4867272e764c5700ed5365a52248227b5c72d756db
MD5 ddf959153d9f36da82a6ae944892b7f1
BLAKE2b-256 dd42b31facac9d37b4c2b2ab0c50965cdfff92acb116969cc4cc6b4197dc5574

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page