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

Username validation

Project description

Username Validation

Username validation methods extracted from django-registration for use outside of django apps (no dependency on django).

James Bennett's post Let’s talk about usernames is a great write-up of both why and how to perform username validation.

This library performs both reserved name checking as well as confusable homohomoglyph checking.

Usage

An Exception will be thrown if the name is confusable or reserved.

All checks

from username_validator import UsernameValidator

# checks both reserved names and confusable
UsernameValidator().validate_all("myname")

Confusable checks only

from username_validator import UsernameValidator

UsernameValidator().validate_confusables_email("myname@something.com")
UsernameValidator().validate_confusables('j\u0430ne_doe') # will throw exception

Reserved name checks only

from username_validator import UsernameValidator

UsernameValidator().validate_reserved("myname")

Custom reserved list

You can add to the reserved list with domain specific names or replace it completely. The default list is broken into categories and exposed, so you can pick and choose if you like.

Extend reserved list with our custom names

UsernameValidator(additional_names=["myspecialname", "myothername"]).validate_reserved("myname")

Replace default list with subset

from username_validator import UsernameValidator, PROTOCOL_HOSTNAMES, SENSITIVE_FILENAMES

UsernameValidator(reserved_names=(PROTOCOL_HOSTNAMES + SENSITIVE_FILENAMES)).validate_all("my_name")

Credit

This code is pretty much a straight copy-paste of django-registration, removing django utility methods. Thank to James Bennett for the excellent work.

Project details


Release history Release notifications

Download files

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

Files for username-validator, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size username_validator-0.0.1.tar.gz (5.0 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