| Server IP : 123.56.80.60 / Your IP : 216.73.216.78 Web Server : Apache/2.4.54 (Win32) OpenSSL/1.1.1s PHP/7.4.33 mod_fcgid/2.3.10-dev System : Windows NT iZhx3sob14hnz7Z 10.0 build 14393 (Windows Server 2016) i586 User : SYSTEM ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Program Files/python/Lib/site-packages/pyotp/ |
Upload File : |
from typing import Any, Optional
from . import utils
from .otp import OTP
class HOTP(OTP):
"""
Handler for HMAC-based OTP counters.
"""
def __init__(self, *args: Any, initial_count: int = 0, **kwargs: Any) -> None:
"""
:param initial_count: starting HMAC counter value, defaults to 0
"""
self.initial_count = initial_count
super(HOTP, self).__init__(*args, **kwargs)
def at(self, count: int) -> str:
"""
Generates the OTP for the given count.
:param count: the OTP HMAC counter
:returns: OTP
"""
return self.generate_otp(count)
def verify(self, otp: str, counter: int) -> bool:
"""
Verifies the OTP passed in against the current counter OTP.
:param otp: the OTP to check against
:param counter: the OTP HMAC counter
"""
return utils.strings_equal(str(otp), str(self.at(counter)))
def provisioning_uri(
self,
name: Optional[str] = None,
initial_count: Optional[int] = None,
issuer_name: Optional[str] = None) -> str:
"""
Returns the provisioning URI for the OTP. This can then be
encoded in a QR Code and used to provision an OTP app like
Google Authenticator.
See also:
https://github.com/google/google-authenticator/wiki/Key-Uri-Format
:param name: name of the user account
:param initial_count: starting HMAC counter value, defaults to 0
:param issuer_name: the name of the OTP issuer; this will be the
organization title of the OTP entry in Authenticator
:returns: provisioning URI
"""
return utils.build_uri(
self.secret,
name=name if name else self.name,
initial_count=initial_count if initial_count else self.initial_count,
issuer=issuer_name if issuer_name else self.issuer,
algorithm=self.digest().name,
digits=self.digits
)