python库来验证适合在面向公共的应用程序中使用的用户名。
python-usernames的Python项目详细描述
python库来验证适合在面向公众环境中使用的用户名 使用的应用程序可以选择登录名和子域。
功能
- 提供默认regex验证器
- 根据banned words的列表进行验证 不应将其用作用户名。
- python 2.6、2.7、3.3、3.4、3.5、pypi
安装
pip install python-usernames
用法
fromusernamesimportis_safe_username>>is_safe_username("jerk")False# contains one of the banned words>>is_safe_username("handsome!")False# contains non-url friendly `!`
是安全的用户名接受以下可选参数:
- regex:必须在禁用的 检查单词。
- whitelist:应始终考虑的单词列表 安全。
- blacklist:应该被视为不安全的单词列表。
默认正则表达式如下:
^ # 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这样的单词将被很好地验证,只有与 那banned word lists 检查。我们不想聪明地避免Scunthorpe problem。 如果你能想出一个算法/解决方案,请创建一个问题/pr:)。
许可证
麻省理工学院