Skip to main content

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.

Metadata

Release files for username-validator 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for username-validator 0.0.1
File Size Uploaded Provenance
username_validator-0.0.1.tar.gz 5.0 kB Without provenance Details

Release files / username_validator-0.0.1.tar.gz

Download URL username_validator-0.0.1.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
2983ff1d17fcb222bf0d455e51251d9c42c70997ac82fe6d12aed8eed6369378
BLAKE2b-256 checksum
How to use checksums
487a716c7c6b8c386a2d5de7774b01506b8fb10e56742826d9dd73ba77f48d54
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for username-validator 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page