本文整理汇总了Python中cryptography.hazmat.primitives.twofactor.totp.TOTP.verify方法的典型用法代码示例。如果您正苦于以下问题:Python TOTP.verify方法的具体用法?Python TOTP.verify怎么用?Python TOTP.verify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cryptography.hazmat.primitives.twofactor.totp.TOTP
的用法示例。
在下文中一共展示了TOTP.verify方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_invalid_verify
# 需要导入模块: from cryptography.hazmat.primitives.twofactor.totp import TOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.totp.TOTP import verify [as 别名]
def test_invalid_verify(self, backend):
secret = b"12345678901234567890"
time = 59
totp = TOTP(secret, 8, hashes.SHA1(), 30, backend)
with pytest.raises(InvalidToken):
totp.verify(b"12345678", time)
示例2: test_verify_sha256
# 需要导入模块: from cryptography.hazmat.primitives.twofactor.totp import TOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.totp.TOTP import verify [as 别名]
def test_verify_sha256(self, backend, params):
secret = params["secret"]
time = int(params["time"])
totp_value = params["totp"]
totp = TOTP(secret, 8, hashes.SHA256(), 30, backend)
assert totp.verify(totp_value, time) is None
示例3: Password
# 需要导入模块: from cryptography.hazmat.primitives.twofactor.totp import TOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.totp.TOTP import verify [as 别名]
"""
Implementación de un sistema que valida tokens TOTP.
Atención: Revisa cuidadosemente la hora del validador/Cliente.
La mayoria de problemas con los tokens TOTP vienen por desfases
temporales entre cliente y servidor
RFC-6238 Time-based One-time Password (TOTP)
"""
import time
import os
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.twofactor.totp import TOTP, InvalidToken
from cryptography.hazmat.primitives.hashes import SHA1
key = b'abcdefghij'
totp = TOTP(key, 6, SHA1(), 30, backend=default_backend())
token = input("Token?: ").encode()
try:
totp.verify(token, time.time())
print("Token Válido")
except InvalidToken:
print("Token Inválido")
示例4: input
# 需要导入模块: from cryptography.hazmat.primitives.twofactor.totp import TOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.totp.TOTP import verify [as 别名]
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:
sys.exit(0)
示例5: verify_totp_code
# 需要导入模块: from cryptography.hazmat.primitives.twofactor.totp import TOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.totp.TOTP import verify [as 别名]
def verify_totp_code(user, code):
totp = TOTP(bytes(user.secret), 6, SHA1(), 30, backend=default_backend())
return totp.verify(force_bytes(code), time.time())