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 | 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
File details
Details for the file username_validator-0.0.1.tar.gz
.
File metadata
- Download URL: username_validator-0.0.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2983ff1d17fcb222bf0d455e51251d9c42c70997ac82fe6d12aed8eed6369378 |
|
MD5 | b5bc59c1b4bdc7c6b60d4e0d1df67362 |
|
BLAKE2b-256 | 487a716c7c6b8c386a2d5de7774b01506b8fb10e56742826d9dd73ba77f48d54 |