Troy Hunt的“我被屏蔽了吗”公共API的接口

pyhibp的Python项目详细描述


pyhibp(pyhave i been pwned)

imageimageimage

与特洛伊·亨特的“我被压过了吗?”(hibp)公共api。对api的完整引用 规范可以在HIBP API Reference找到。

此模块检测何时达到API的速率限制,并在达到该限制时引发运行时错误 已超过,或者根据提交的数据遇到另一个API定义的错误条件时。什么时候? 从调用中找到数据,返回的数据将采用从端点检索的格式,并记录 在相关函数的返回类型信息中。

注意,pwnedpasswordsapi后端没有速率限制。如果您打算批量查询密码或 散列,您应该考虑下载可以通过Pwned Passwords页访问的原始数据文件。

安装

$ pip install pyhibp

示例用法

对于交互式示例,请查看jupyter笔记本中的^{}, 以及^{}

importpyhibpfrompyhibpimportpwnedpasswordsaspw# Required: A descriptive user agent must be set describing the application consuming#   the HIBP APIpyhibp.set_user_agent(ua="Awesome application/0.0.1 (An awesome description)")# Check a password to see if it has been disclosed in a public breach corpusresp=pw.is_password_breached(password="secret")ifresp:print("Password breached!")print("This password was used {0} time(s) before.".format(resp))# Get data classes in the HIBP systemresp=pyhibp.get_data_classes()# Get all breach informationresp=pyhibp.get_all_breaches()# Get a single breachresp=pyhibp.get_single_breach(breach_name="Adobe")# An API key is required for calls which search by email address#   (so get_pastes/get_account_breaches)# See <https://haveibeenpwned.com/API/Key>HIBP_API_KEY=NoneifHIBP_API_KEY:# Set the API key prior to using the functions which require it.pyhibp.set_api_key(key=HIBP_API_KEY)# Get pastes affecting a given email addressresp=pyhibp.get_pastes(email_address="test@example.com")# Get breaches that affect a given accountresp=pyhibp.get_account_breaches(account="test@example.com",truncate_response=True)

开发

这个项目目前打算与Python2和Python3兼容。因此,我们通过pipenv使用虚拟环境。 要开发或测试,请执行以下操作:

# Install the prerequisite virtual environment provider
$ pip install pipenv
# Initialize the pipenv environment and install the module within it
$ make dev
# To run PEP8, tests, and check the manifest
$ make tox

其他命令可以在Makefile中找到。

目标

  • 同步到最新的hibp api,在有意义的地方实现端点访问函数。例如, 为了安全起见,没有实现向pwned密码端点提交sha-1的功能。见 下面的“关于密码检查”了解更多详细信息。
  • 对于违反和粘贴,充当中介;返回从服务接收到的json。

关于密码检查

  • 对于密码,提供了提供要检查的明文密码的选项,以方便实现。
  • 为了增加安全性,pwnedpasswords.is_password_breached()只传输sha-1的前五个字符 散列到pwned passwords api端点;安全密码将保持安全,而不会泄露完整的散列。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
CentOS上的java Spring Boot简易应用程序需要很长时间才能启动   java如何检查字符串值是否等于null?   收集器中的java映射值。分组方式()   java需要支持Azure AD B2C webapp集成   java如何加入线程以停止它?   java如何使用意图传递类的对象?   java如何在战争环境中发现CDI生产者?   多模块项目中java奇怪的编译器行为   java如何在web应用程序中管理密码?   java从http服务器、filehandler中删除冗余代码   java使用反射来获取泛型类的字段   java Spring MVC/Hibernate/MySQL 400错误请求错误   给定正整数a的java幂为3   在Java中将元素拆分为不同数量的列表?   java展开折叠窗格