Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

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.

Files for python-usernames, version 0.2.3
Filename, size File type Python version Upload date Hashes
Filename, size python_usernames-0.2.3-py2.py3-none-any.whl (7.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size python-usernames-0.2.3.tar.gz (5.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page