本文整理汇总了Python中cryptography.hazmat.primitives.twofactor.hotp.HOTP.get_provisioning_uri方法的典型用法代码示例。如果您正苦于以下问题:Python HOTP.get_provisioning_uri方法的具体用法?Python HOTP.get_provisioning_uri怎么用?Python HOTP.get_provisioning_uri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptography.hazmat.primitives.twofactor.hotp.HOTP
的用法示例。
在下文中一共展示了HOTP.get_provisioning_uri方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_provisioning_uri
# 需要导入模块: from cryptography.hazmat.primitives.twofactor.hotp import HOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.hotp.HOTP import get_provisioning_uri [as 别名]
def test_get_provisioning_uri(self, backend):
secret = b"12345678901234567890"
hotp = HOTP(secret, 6, SHA1(), backend)
assert hotp.get_provisioning_uri("Alice Smith", 1, None) == (
"otpauth://hotp/Alice%20Smith?digits=6&secret=GEZDGNBV"
"GY3TQOJQGEZDGNBVGY3TQOJQ&algorithm=SHA1&counter=1")
assert hotp.get_provisioning_uri("Alice Smith", 1, 'Foo') == (
"otpauth://hotp/Foo:Alice%20Smith?digits=6&secret=GEZD"
"GNBVGY3TQOJQGEZDGNBVGY3TQOJQ&algorithm=SHA1&issuer=Foo"
"&counter=1")
示例2: input
# 需要导入模块: from cryptography.hazmat.primitives.twofactor.hotp import HOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.hotp.HOTP import get_provisioning_uri [as 别名]
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.twofactor.hotp import HOTP
from cryptography.hazmat.primitives.hashes import SHA1
from cryptography.hazmat.primitives.twofactor import InvalidToken
import pyqrcode
key = os.urandom(16)
counter = 1
issuer = 'GruPyPR'
account_name = input('Your name: ')
hotp = HOTP(key, 6, SHA1(), backend=default_backend())
uri = hotp.get_provisioning_uri(account_name, counter, issuer)
url = pyqrcode.create(uri)
print('Scan this!\n')
url.svg('hotp.svg', scale=8)
webbrowser.open('hotp.svg')
while True:
try:
hotp_value = bytes(input('Two factor password: '), encoding='utf-8')
hotp.verify(hotp_value, counter)
print('You are authenticated!\n')
except InvalidToken:
print('You shall not pass!\n')
continue
except KeyboardInterrupt:
sys.exit(0)