Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ogrodnek/username_validator
https://github.com/ogrodnek/username_validator
aws cognito cognito-user-pool lambda python
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/ogrodnek/username_validator
- Owner: ogrodnek
- License: bsd-3-clause
- Created: 2018-10-10T00:26:03.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-08-11T15:18:29.000Z (over 3 years ago)
- Last Synced: 2024-10-07T14:19:27.420Z (3 months ago)
- Topics: aws, cognito, cognito-user-pool, lambda, python
- Language: Python
- Size: 6.84 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
Username Validation
========Username validation methods extracted from [django-registration](https://github.com/ubernostrum/django-registration) for use outside of django apps (no dependency on django).
[James Bennett](https://github.com/ubernostrum)'s post [Let’s talk about usernames](https://www.b-list.org/weblog/2018/feb/11/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](https://confusable-homoglyphs.readthedocs.io/en/latest/readme.html) 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 UsernameValidatorUsernameValidator().validate_confusables_email("[email protected]")
UsernameValidator().validate_confusables('j\u0430ne_doe') # will throw exception```
## Reserved name checks only
```
from username_validator import UsernameValidatorUsernameValidator().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_FILENAMESUsernameValidator(reserved_names=(PROTOCOL_HOSTNAMES + SENSITIVE_FILENAMES)).validate_all("my_name")
```## Credit
This code is pretty much a straight copy-paste of [django-registration](https://github.com/ubernostrum/django-registration), removing django utility methods. Thank to [James Bennett](https://github.com/ubernostrum) for the excellent work.