实现hotp/totp的两步验证

otpauth的Python项目详细描述


cryptography现在有内置的双因素支持。

otpauth是一次性密码验证,通常称为 两步验证。你可能从google,dropbox和 等

Wheel StatusLatest VersionTravis CI StatusCoverage StatusApp Veyor CI Status

安装

使用pip

$ pip install otpauth

或者,使用easy_install

$ easy_install otpauth

用法

生成并验证otp代码非常简单:

>>> from otpauth import OtpAuth
>>> auth = OtpAuth('secret')  # a secret string
>>> auth.hotp()  # generate a count based code, default count is 4
330810
>>> auth.valid_hotp(330810)
4
>>> auth.hotp(2)  # generate a count based code, count is 2
720111
>>> auth.valid_hotp(720111)
2
>>> auth.totp()  # generate a time based code
828657
>>> auth.valid_totp(828657)
True

验证器

您可以创建一个二维码,供google authenticator扫描:

>>> from otpauth import OtpAuth
>>> auth = OtpAuth('secret')  # a secret string
>>> s = auth.to_uri('totp', 'Example:foo@bar.baz', 'Foo')
>>> import qrcode
>>> img = qrcode.make(s)

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

推荐PyPI第三方库


热门话题
java使用jackson序列化/反序列化具有不同属性的子属性   javascript驱动程序。getTitle()从错误页面获取数据   java web应用程序的增量部署   java字符引用“&#x10”是无效的XML字符   java MyEclipse+Hibernate不按ID排序属性集?   找不到IBM Filenet P8更改预处理器Java实现   java比较器,用于按浮点参数对对象arraylist排序   java如何调试。来自eclipse或其他版本的bsh文件   不允许使用java rest api post方法   java如何在Servlet中打开弹出窗口,然后重定向页面   java的replaceAll方法对我不起作用我做错了什么?   我收到了javax。网ssl。SSLHandshakeException:握手期间远程主机关闭连接