Skip to main content

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

Project description

Build Status Coverage Status PyPI version PyPI

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.6, 2.7, 3.3, 3.4, 3.5, 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

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.1.tar.gz (5.6 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for python-usernames-0.2.1.tar.gz
Algorithm Hash digest
SHA256 5b657e330926371c9cc86237c4faf7176ef21757de63a52db53cdae3623f5cc1
MD5 2045917bc67e40723ddaffc67d726e22
BLAKE2b-256 8ac91b70dafcf9e20c514f9a41f8ab18f988fb62623cac47a09e7f9b1a69efc7

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