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


Python totp.TOTP类代码示例

本文整理汇总了Python中cryptography.hazmat.primitives.twofactor.totp.TOTP的典型用法代码示例。如果您正苦于以下问题:Python TOTP类的具体用法?Python TOTP怎么用?Python TOTP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_generate_sha512

    def test_generate_sha512(self, backend, params):
        secret = params["secret"]
        time = int(params["time"])
        totp_value = params["totp"]

        totp = TOTP(secret, 8, hashes.SHA512(), 30, backend)
        assert totp.generate(time) == totp_value
开发者ID:Ayrx,项目名称:cryptography,代码行数:7,代码来源:test_totp.py

示例2: test_floating_point_time_generate

    def test_floating_point_time_generate(self, backend):
        secret = b"12345678901234567890"
        time = 59.1

        totp = TOTP(secret, 8, hashes.SHA1(), 30, backend)

        assert totp.generate(time) == b"94287082"
开发者ID:Ayrx,项目名称:cryptography,代码行数:7,代码来源:test_totp.py

示例3: test_verify_sha256

    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
开发者ID:Ayrx,项目名称:cryptography,代码行数:8,代码来源:test_totp.py

示例4: test_invalid_verify

    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)
开发者ID:Ayrx,项目名称:cryptography,代码行数:8,代码来源:test_totp.py

示例5: test_get_provisioning_uri

    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")
开发者ID:Ayrx,项目名称:cryptography,代码行数:12,代码来源:test_totp.py

示例6: Totp

    def Totp(self, key):
        # simple constructor helper

        if not key:
            key = os.urandom(20)  # == 160 bytes which is recommended

        totp = TOTP(key,
                    asint(config.get('auth.multifactor.totp.length', 6)),
                    SHA1(),
                    asint(config.get('auth.multifactor.totp.time', 30)),
                    backend=default_backend())

        totp.key = key  # for convenience, else you have to use `totp._hotp._key`

        return totp
开发者ID:apache,项目名称:allura,代码行数:15,代码来源:multifactor.py

示例7: Password

""" 
    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")

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

示例8: input

from cryptography.hazmat.backends import default_backend
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!')
开发者ID:GaragemHacker,项目名称:two-factor,代码行数:30,代码来源:totp.py

示例9: TOTP

#!/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)

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

示例10: test_buffer_protocol

 def test_buffer_protocol(self, backend):
     key = bytearray(b"a long key with lots of entropy goes here")
     totp = TOTP(key, 8, hashes.SHA512(), 30, backend)
     time = 60
     assert totp.generate(time) == b"53049576"
开发者ID:pyca,项目名称:cryptography,代码行数:5,代码来源:test_totp.py

示例11: verify_totp_code

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())
开发者ID:keybar,项目名称:keybar,代码行数:3,代码来源:totp.py

示例12: test_verify_totp_failure

def test_verify_totp_failure(skew):
    secret = generate_totp_secret()
    totp = TOTP(secret, TOTP_LENGTH, SHA1(), TOTP_INTERVAL, backend=default_backend())
    value = totp.generate(time.time() + skew)
    assert not verify_totp(secret, value)
开发者ID:craig5,项目名称:warehouse,代码行数:5,代码来源:test_otp.py


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