适用于公共应用程序的Python库,用于验证用户名。
项目描述
python-usernames
适用于公共应用程序的Python库,用于验证用户名,其中用户可以选择登录名和子域名。
功能
- 提供默认的正则表达式验证器
- 验证列表中的禁止使用的单词,这些单词不应作为用户名使用。
- Python 3.8+
安装
pip install python-usernames
用法
from python_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接受以下可选参数
-
whitelist
:一个不区分大小写的单词列表,应被视为始终安全。默认:[]
-
blacklist
:一个不区分大小写的单词列表,应被视为不安全。默认:[]
-
max_length
:指定用户名可以有的最大字符数。默认:None
-
regex
:必须通过的正则表达式字符串,然后再检查禁止使用的单词。
默认的正则表达式如下
^ # 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
进一步阅读
注意事项
像 bigcock12
这样的单词可以正常验证,只需检查是否与 禁用词列表 相等。我们不会试图聪明地避免 Scunthorpe 问题。如果您可以提出算法/解决方案,请创建 issue/pr :)。
许可协议
MIT
项目详情
关闭
python_usernames-1.0.0.tar.gz 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 82c68b9dccb6d0571eded31fe47b91ebca4b25e530a8703e8c06ebd9198f3f4f |
|
MD5 | c5a8f98aaf89254491f288c7e96fd7d8 |
|
BLAKE2b-256 | e40daad0e8609ad208f3972d9032266f452e04ef9919f8db7f9dab06f49782c7 |
关闭
python_usernames-1.0.0-py3-none-any.whl 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 59fd41670d8ee550f93be1db25fb0112591b0566c44069d6d42ad26a5c71b474 |
|
MD5 | 64ac70942f76381c0e46d4b1167631fb |
|
BLAKE2b-256 | 5f4fd0f708985dceefcb8e9cb1eefe2b5f3d88b624ec927bb85fa69f89de8f50 |