当前位置: 首页>>代码示例>>Python>>正文


Python HOTP.verify方法代码示例

本文整理汇总了Python中cryptography.hazmat.primitives.twofactor.hotp.HOTP.verify方法的典型用法代码示例。如果您正苦于以下问题:Python HOTP.verify方法的具体用法?Python HOTP.verify怎么用?Python HOTP.verify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cryptography.hazmat.primitives.twofactor.hotp.HOTP的用法示例。


在下文中一共展示了HOTP.verify方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_hotp_value

# 需要导入模块: from cryptography.hazmat.primitives.twofactor.hotp import HOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.hotp.HOTP import verify [as 别名]
def check_hotp_value(hotp_token):
	"""
	Verify the HOTP token from the AS
	"""
	logger.info("Loading 2FA secret from %s", auth_secretfile)
	# Load the shared secret and counter from file
	with open(auth_secretfile, 'r') as f:
		content = json.loads(f.read())
		secret = content['2FAKey']
		counter = content['Counter']
	logger.info("Loaded 2FA secret")
	hotp = HOTP(bytes(secret, 'utf-8'), 6, hashes.SHA1(), backend=default_backend())
	logger.info("Trying to verify HOTP token")
	try:
		# Try to verify the token
		hotp.verify(hotp=bytes(hotp_token, 'utf-8'), counter=counter)
		# Verification failure would have raised an InvalidToken exception here
		logger.info("HOTP token successfully authenticated")
		# Save the updated secret to file
		counter += 1	# Increment the counter
		content['Counter'] = counter
		logger.info("HOTP counter updated to: %s", counter)
		with open(auth_secretfile, 'w') as f:	# Write to file
			f.write(json.dumps(content))
		return True
	except InvalidToken:
		logger.warning("HOTP token was not authenticated")
		return False
开发者ID:DroidX86,项目名称:CloudSec,代码行数:30,代码来源:ags.py

示例2: test_invalid_verify

# 需要导入模块: from cryptography.hazmat.primitives.twofactor.hotp import HOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.hotp.HOTP import verify [as 别名]
    def test_invalid_verify(self, backend):
        secret = b"12345678901234567890"
        counter = 0

        hotp = HOTP(secret, 6, SHA1(), backend)

        with pytest.raises(InvalidToken):
            hotp.verify(b"123456", counter)
开发者ID:B-Rich,项目名称:cryptography,代码行数:10,代码来源:test_hotp.py

示例3: test_verify

# 需要导入模块: from cryptography.hazmat.primitives.twofactor.hotp import HOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.hotp.HOTP import verify [as 别名]
    def test_verify(self, backend, params):
        secret = params["secret"]
        counter = int(params["counter"])
        hotp_value = params["hotp"]

        hotp = HOTP(secret, 6, SHA1(), backend)

        assert hotp.verify(hotp_value, counter) is None
开发者ID:B-Rich,项目名称:cryptography,代码行数:10,代码来源:test_hotp.py

示例4: input

# 需要导入模块: from cryptography.hazmat.primitives.twofactor.hotp import HOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.hotp.HOTP import verify [as 别名]
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)
开发者ID:GaragemHacker,项目名称:two-factor,代码行数:32,代码来源:hotp.py

示例5: Password

# 需要导入模块: from cryptography.hazmat.primitives.twofactor.hotp import HOTP [as 别名]
# 或者: from cryptography.hazmat.primitives.twofactor.hotp.HOTP import verify [as 别名]
    RFC-4226 HMAC-Based One-time Password (HOTP)
"""

import os
import base64

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.twofactor.hotp import HOTP, InvalidToken
from cryptography.hazmat.primitives.hashes import SHA1

key = b'abcdefghij'
hotp = HOTP(key, 6, SHA1(), backend=default_backend())
token = input("Introduce Token: ").encode('utf-8')
valido = False

for counter in range(0, 100):
   try:
       hotp.verify(token, counter)
       valido = True
   except InvalidToken:
       pass


if valido:
   print("Token Válido")
else:
   print("Token Inválido")


开发者ID:luisgf,项目名称:pyvigo-cryptography,代码行数:29,代码来源:hotp.py


注:本文中的cryptography.hazmat.primitives.twofactor.hotp.HOTP.verify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。