本文整理汇总了Python中cryptography.hazmat.primitives.twofactor.totp.TOTP.get_provisioning_uri方法的典型用法代码示例。如果您正苦于以下问题:Python TOTP.get_provisioning_uri方法的具体用法?Python TOTP.get_provisioning_uri怎么用?Python TOTP.get_provisioning_uri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptography.hazmat.primitives.twofactor.totp.TOTP
的用法示例。
在下文中一共展示了TOTP.get_provisioning_uri方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_provisioning_uri
# 需要导入模块: from cryptography.hazmat.primitives.twofactor.totp import TOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.totp.TOTP import get_provisioning_uri [as 别名]
def test_get_provisioning_uri(self, backend):
secret = b"12345678901234567890"
totp = TOTP(secret, 6, hashes.SHA1(), 30, backend=backend)
assert totp.get_provisioning_uri("Alice Smith", None) == (
"otpauth://totp/Alice%20Smith?digits=6&secret=GEZDGNBVG"
"Y3TQOJQGEZDGNBVGY3TQOJQ&algorithm=SHA1&period=30")
assert totp.get_provisioning_uri("Alice Smith", 'World') == (
"otpauth://totp/World:Alice%20Smith?digits=6&secret=GEZ"
"DGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&algorithm=SHA1&issuer=World"
"&period=30")
示例2: input
# 需要导入模块: from cryptography.hazmat.primitives.twofactor.totp import TOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.totp.TOTP import get_provisioning_uri [as 别名]
from cryptography.hazmat.primitives.twofactor.totp import TOTP
from cryptography.hazmat.primitives.hashes import SHA1
from cryptography.hazmat.primitives.twofactor import InvalidToken
import pyqrcode
key = os.urandom(16)
counter = 1
time_value = time.time()
issuer = 'GruPyPR'
account_name = input('Your name: ')
totp = TOTP(key, 6, SHA1(), 30, backend=default_backend())
uri = totp.get_provisioning_uri(account_name, issuer)
url = pyqrcode.create(uri)
print('Scan this!\n')
url.svg('totp.svg', scale=8)
webbrowser.open('totp.svg')
while True:
try:
totp_value = bytes(input('Two factor password: '), encoding='utf-8')
totp.verify(totp_value, time.time())
print('You are authenticated!\n')
except InvalidToken:
print('You shall not pass!')
continue
except KeyboardInterrupt:
示例3: TOTP
# 需要导入模块: from cryptography.hazmat.primitives.twofactor.totp import TOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.totp.TOTP import get_provisioning_uri [as 别名]
#!/usr/bin/env python3
""" Genera un QR TOTP compatible con Google Authenticator """
import webbrowser
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.hashes import SHA1
from cryptography.hazmat.primitives.twofactor.totp import TOTP
google_url = 'http://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl='
cuenta = '[email protected]'
expedida_por = None
key = b'abcdefghij'
totp = TOTP(key, 8, SHA1(), 30, backend=default_backend())
uri = totp.get_provisioning_uri(cuenta, expedida_por)
url = '%s%s' % (google_url, uri)
webbrowser.open(url)