pax_global_header00006660000000000000000000000064140412704470014515gustar00rootroot0000000000000052 comment=8c7fccc6b0df4d457c16075da44fe248c6f117cf onetimepass-1.0.1/000077500000000000000000000000001404127044700140435ustar00rootroot00000000000000onetimepass-1.0.1/PKG-INFO000066400000000000000000000206531404127044700151460ustar00rootroot00000000000000Metadata-Version: 1.1 Name: onetimepass Version: 1.0.1 Summary: Module for generating and validating HOTP and TOTP tokens Home-page: https://github.com/tadeck/onetimepass/ Author: Tomasz Jaskowski Author-email: tadeck@gmail.com License: MIT Download-URL: https://github.com/tadeck/onetimepass/archive/v1.0.0.tar.gz Description: Versions ======== Current development release: `onetimepass-master.tar.gz`_ |otp-status-dev|_ .. |otp-status-dev| image:: https://api.travis-ci.org/tadeck/onetimepass.png?branch=master .. _otp-status-dev: https://travis-ci.org/tadeck/onetimepass .. _onetimepass-master.tar.gz: https://github.com/tadeck/onetimepass/archive/master.tar.gz Changelog --------- +---------+------------+------------------------------------------------------+ | Version | Date | Changes | +=========+============+======================================================+ | 1.0.1 | 2015-07-31 | - fixed tests and build system, | | | | - extended test coverage with Py3.5, PyPy and PyPy3, | +---------+------------+------------------------------------------------------+ | 1.0.0 | 2015-07-31 | - skipping spaces if they are given in secret, | | | | - test suite made more reliable, | +---------+------------+------------------------------------------------------+ | 0.3.0 | 2014-08-16 | - configurable digest method, | | | | - configurable token length, | | | | - configurable TOTP interval length, | +---------+------------+------------------------------------------------------+ | 0.2.2 | 2013-07-12 | - license clarification, | | | | - removal of compiled documentation from the sources,| +---------+------------+------------------------------------------------------+ | 0.2.1 | 2013-07-12 | - support for unicode secrets, | | | | - preliminary support for Travis CI, | +---------+------------+------------------------------------------------------+ | 0.2.0 | 2013-04-11 | - added compatibility with Python 3.x, | | | | - removed compatibility with Python 2.5 and earlier, | +---------+------------+------------------------------------------------------+ | 0.1.2 | 2013-01-23 | - added automated case fold to secret, | +---------+------------+------------------------------------------------------+ | 0.1.1 | 2013-12-20 | - internal code improvements, | | | | - documentation, | +---------+------------+------------------------------------------------------+ | 0.1.0 | 2011-12-19 | (initial public release) | +---------+------------+------------------------------------------------------+ What is OneTimePass =================== OneTimePass (actually ``onetimepass``) is a module for generating one-time passwords, namely HOTPs (HMAC-based one-time passwords) and TOTPs (time-based one-time passwords). They are used eg. within Google Authenticator application for Android or iPhone. How to install ============== To install the library, you can either use ``pip``, or just download it separately. Installing in ``pip`` is the simplest. Assuming you are installing it system-wide:: $ sudo pip install onetimepass (if you are installing it in virtualenv, you do not need "``sudo``" part). Alternatively, you can follow the download link above and unpack in some directory on your ``sys.path``, or clone it as Git submodule to your own directory. How to use OneTimePass ====================== You can use this module in the following way: 1. Install module (download it into your application's directory or into modules directory) 2. To get time-based token you invoke it like that:: import onetimepass as otp my_secret = 'MFRGGZDFMZTWQ2LK' my_token = otp.get_totp(my_secret) .. note:: ``my_secret`` is case-insensitive, also spaces are ignored. This means you can provide your users with more readable representations of the secrets (eg. ``mfrg gzdf mztw q2lk`` instead of ``MFRGGZDFMZTWQ2LK``) and pass them unchanged to library. Same applies to other functions accepting secrets in this library. 3. To get HMAC-based token you invoke it like that:: import onetimepass as otp my_secret = 'MFRGGZDFMZTWQ2LK' my_token = otp.get_hotp(my_secret, intervals_no=3) where ``intervals_no`` is the number of the current trial (if checking on the server, you have to check several values, higher than the last successful one, determined for previous successful authentications). 4. To check time-based token you invoke it like that:: import onetimepass as otp my_secret = 'MFRGGZDFMZTWQ2LK' my_token = 123456 # should be probably from some user's input is_valid = otp.valid_totp(token=my_token, secret=my_secret) 5. To check HMAC-based token you invoke it like that:: import onetimepass as otp my_secret = 'MFRGGZDFMZTWQ2LK' my_token = 123456 # should be probably from some user's input last_used = 5 # store last valid interval somewhere else is_valid = otp.valid_hotp(token=my_token, secret=my_secret, last=last_used) where: - ``last`` argument (in this case being assigned ``last_used``) is the number of the last successfully checked interval number (as ``valid_totp()`` will skip it and start checking from the next interval number) - ``is_valid`` is being assigned value of ``False`` if ``my_token`` has not been identified as valid OTP for given secret (``my_secret``) and checked interval range. If it has been successful, ``is_valid`` is assigned a number of the working interval number (it should be saved into the database and supplied to the function as ``last`` argument next time the password is being checked, so you cannot use the same token again). License ======= License for this library is available in ``LICENSE.rst`` file, in the same directory. Online version is available here_. .. _here: https://github.com/tadeck/onetimepass/blob/master/README.rst Platform: UNKNOWN Classifier: Development Status :: 6 - Mature Classifier: Intended Audience :: Developers Classifier: Intended Audience :: Education Classifier: Intended Audience :: Financial and Insurance Industry Classifier: Intended Audience :: Healthcare Industry Classifier: Intended Audience :: Information Technology Classifier: Intended Audience :: Legal Industry Classifier: Intended Audience :: Science/Research Classifier: Intended Audience :: System Administrators Classifier: Intended Audience :: Telecommunications Industry Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Topic :: Internet :: WWW/HTTP :: Session Classifier: Topic :: Internet :: WWW/HTTP :: Site Management Classifier: Topic :: Security Classifier: Topic :: Software Development :: Libraries Classifier: Topic :: Software Development :: Libraries :: Python Modules onetimepass-1.0.1/README.rst000066400000000000000000000136731404127044700155440ustar00rootroot00000000000000Versions ======== Current development release: `onetimepass-master.tar.gz`_ |otp-status-dev|_ .. |otp-status-dev| image:: https://api.travis-ci.org/tadeck/onetimepass.png?branch=master .. _otp-status-dev: https://travis-ci.org/tadeck/onetimepass .. _onetimepass-master.tar.gz: https://github.com/tadeck/onetimepass/archive/master.tar.gz Changelog --------- +---------+------------+------------------------------------------------------+ | Version | Date | Changes | +=========+============+======================================================+ | 1.0.1 | 2015-07-31 | - fixed tests and build system, | | | | - extended test coverage with Py3.5, PyPy and PyPy3, | +---------+------------+------------------------------------------------------+ | 1.0.0 | 2015-07-31 | - skipping spaces if they are given in secret, | | | | - test suite made more reliable, | +---------+------------+------------------------------------------------------+ | 0.3.0 | 2014-08-16 | - configurable digest method, | | | | - configurable token length, | | | | - configurable TOTP interval length, | +---------+------------+------------------------------------------------------+ | 0.2.2 | 2013-07-12 | - license clarification, | | | | - removal of compiled documentation from the sources,| +---------+------------+------------------------------------------------------+ | 0.2.1 | 2013-07-12 | - support for unicode secrets, | | | | - preliminary support for Travis CI, | +---------+------------+------------------------------------------------------+ | 0.2.0 | 2013-04-11 | - added compatibility with Python 3.x, | | | | - removed compatibility with Python 2.5 and earlier, | +---------+------------+------------------------------------------------------+ | 0.1.2 | 2013-01-23 | - added automated case fold to secret, | +---------+------------+------------------------------------------------------+ | 0.1.1 | 2013-12-20 | - internal code improvements, | | | | - documentation, | +---------+------------+------------------------------------------------------+ | 0.1.0 | 2011-12-19 | (initial public release) | +---------+------------+------------------------------------------------------+ What is OneTimePass =================== OneTimePass (actually ``onetimepass``) is a module for generating one-time passwords, namely HOTPs (HMAC-based one-time passwords) and TOTPs (time-based one-time passwords). They are used eg. within Google Authenticator application for Android or iPhone. How to install ============== To install the library, you can either use ``pip``, or just download it separately. Installing in ``pip`` is the simplest. Assuming you are installing it system-wide:: $ sudo pip install onetimepass (if you are installing it in virtualenv, you do not need "``sudo``" part). Alternatively, you can follow the download link above and unpack in some directory on your ``sys.path``, or clone it as Git submodule to your own directory. How to use OneTimePass ====================== You can use this module in the following way: 1. Install module (download it into your application's directory or into modules directory) 2. To get time-based token you invoke it like that:: import onetimepass as otp my_secret = 'MFRGGZDFMZTWQ2LK' my_token = otp.get_totp(my_secret) .. note:: ``my_secret`` is case-insensitive, also spaces are ignored. This means you can provide your users with more readable representations of the secrets (eg. ``mfrg gzdf mztw q2lk`` instead of ``MFRGGZDFMZTWQ2LK``) and pass them unchanged to library. Same applies to other functions accepting secrets in this library. 3. To get HMAC-based token you invoke it like that:: import onetimepass as otp my_secret = 'MFRGGZDFMZTWQ2LK' my_token = otp.get_hotp(my_secret, intervals_no=3) where ``intervals_no`` is the number of the current trial (if checking on the server, you have to check several values, higher than the last successful one, determined for previous successful authentications). 4. To check time-based token you invoke it like that:: import onetimepass as otp my_secret = 'MFRGGZDFMZTWQ2LK' my_token = 123456 # should be probably from some user's input is_valid = otp.valid_totp(token=my_token, secret=my_secret) 5. To check HMAC-based token you invoke it like that:: import onetimepass as otp my_secret = 'MFRGGZDFMZTWQ2LK' my_token = 123456 # should be probably from some user's input last_used = 5 # store last valid interval somewhere else is_valid = otp.valid_hotp(token=my_token, secret=my_secret, last=last_used) where: - ``last`` argument (in this case being assigned ``last_used``) is the number of the last successfully checked interval number (as ``valid_totp()`` will skip it and start checking from the next interval number) - ``is_valid`` is being assigned value of ``False`` if ``my_token`` has not been identified as valid OTP for given secret (``my_secret``) and checked interval range. If it has been successful, ``is_valid`` is assigned a number of the working interval number (it should be saved into the database and supplied to the function as ``last`` argument next time the password is being checked, so you cannot use the same token again). License ======= License for this library is available in ``LICENSE.rst`` file, in the same directory. Online version is available here_. .. _here: https://github.com/tadeck/onetimepass/blob/master/README.rst onetimepass-1.0.1/onetimepass.egg-info/000077500000000000000000000000001404127044700200645ustar00rootroot00000000000000onetimepass-1.0.1/onetimepass.egg-info/PKG-INFO000066400000000000000000000206531404127044700211670ustar00rootroot00000000000000Metadata-Version: 1.1 Name: onetimepass Version: 1.0.1 Summary: Module for generating and validating HOTP and TOTP tokens Home-page: https://github.com/tadeck/onetimepass/ Author: Tomasz Jaskowski Author-email: tadeck@gmail.com License: MIT Download-URL: https://github.com/tadeck/onetimepass/archive/v1.0.0.tar.gz Description: Versions ======== Current development release: `onetimepass-master.tar.gz`_ |otp-status-dev|_ .. |otp-status-dev| image:: https://api.travis-ci.org/tadeck/onetimepass.png?branch=master .. _otp-status-dev: https://travis-ci.org/tadeck/onetimepass .. _onetimepass-master.tar.gz: https://github.com/tadeck/onetimepass/archive/master.tar.gz Changelog --------- +---------+------------+------------------------------------------------------+ | Version | Date | Changes | +=========+============+======================================================+ | 1.0.1 | 2015-07-31 | - fixed tests and build system, | | | | - extended test coverage with Py3.5, PyPy and PyPy3, | +---------+------------+------------------------------------------------------+ | 1.0.0 | 2015-07-31 | - skipping spaces if they are given in secret, | | | | - test suite made more reliable, | +---------+------------+------------------------------------------------------+ | 0.3.0 | 2014-08-16 | - configurable digest method, | | | | - configurable token length, | | | | - configurable TOTP interval length, | +---------+------------+------------------------------------------------------+ | 0.2.2 | 2013-07-12 | - license clarification, | | | | - removal of compiled documentation from the sources,| +---------+------------+------------------------------------------------------+ | 0.2.1 | 2013-07-12 | - support for unicode secrets, | | | | - preliminary support for Travis CI, | +---------+------------+------------------------------------------------------+ | 0.2.0 | 2013-04-11 | - added compatibility with Python 3.x, | | | | - removed compatibility with Python 2.5 and earlier, | +---------+------------+------------------------------------------------------+ | 0.1.2 | 2013-01-23 | - added automated case fold to secret, | +---------+------------+------------------------------------------------------+ | 0.1.1 | 2013-12-20 | - internal code improvements, | | | | - documentation, | +---------+------------+------------------------------------------------------+ | 0.1.0 | 2011-12-19 | (initial public release) | +---------+------------+------------------------------------------------------+ What is OneTimePass =================== OneTimePass (actually ``onetimepass``) is a module for generating one-time passwords, namely HOTPs (HMAC-based one-time passwords) and TOTPs (time-based one-time passwords). They are used eg. within Google Authenticator application for Android or iPhone. How to install ============== To install the library, you can either use ``pip``, or just download it separately. Installing in ``pip`` is the simplest. Assuming you are installing it system-wide:: $ sudo pip install onetimepass (if you are installing it in virtualenv, you do not need "``sudo``" part). Alternatively, you can follow the download link above and unpack in some directory on your ``sys.path``, or clone it as Git submodule to your own directory. How to use OneTimePass ====================== You can use this module in the following way: 1. Install module (download it into your application's directory or into modules directory) 2. To get time-based token you invoke it like that:: import onetimepass as otp my_secret = 'MFRGGZDFMZTWQ2LK' my_token = otp.get_totp(my_secret) .. note:: ``my_secret`` is case-insensitive, also spaces are ignored. This means you can provide your users with more readable representations of the secrets (eg. ``mfrg gzdf mztw q2lk`` instead of ``MFRGGZDFMZTWQ2LK``) and pass them unchanged to library. Same applies to other functions accepting secrets in this library. 3. To get HMAC-based token you invoke it like that:: import onetimepass as otp my_secret = 'MFRGGZDFMZTWQ2LK' my_token = otp.get_hotp(my_secret, intervals_no=3) where ``intervals_no`` is the number of the current trial (if checking on the server, you have to check several values, higher than the last successful one, determined for previous successful authentications). 4. To check time-based token you invoke it like that:: import onetimepass as otp my_secret = 'MFRGGZDFMZTWQ2LK' my_token = 123456 # should be probably from some user's input is_valid = otp.valid_totp(token=my_token, secret=my_secret) 5. To check HMAC-based token you invoke it like that:: import onetimepass as otp my_secret = 'MFRGGZDFMZTWQ2LK' my_token = 123456 # should be probably from some user's input last_used = 5 # store last valid interval somewhere else is_valid = otp.valid_hotp(token=my_token, secret=my_secret, last=last_used) where: - ``last`` argument (in this case being assigned ``last_used``) is the number of the last successfully checked interval number (as ``valid_totp()`` will skip it and start checking from the next interval number) - ``is_valid`` is being assigned value of ``False`` if ``my_token`` has not been identified as valid OTP for given secret (``my_secret``) and checked interval range. If it has been successful, ``is_valid`` is assigned a number of the working interval number (it should be saved into the database and supplied to the function as ``last`` argument next time the password is being checked, so you cannot use the same token again). License ======= License for this library is available in ``LICENSE.rst`` file, in the same directory. Online version is available here_. .. _here: https://github.com/tadeck/onetimepass/blob/master/README.rst Platform: UNKNOWN Classifier: Development Status :: 6 - Mature Classifier: Intended Audience :: Developers Classifier: Intended Audience :: Education Classifier: Intended Audience :: Financial and Insurance Industry Classifier: Intended Audience :: Healthcare Industry Classifier: Intended Audience :: Information Technology Classifier: Intended Audience :: Legal Industry Classifier: Intended Audience :: Science/Research Classifier: Intended Audience :: System Administrators Classifier: Intended Audience :: Telecommunications Industry Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Topic :: Internet :: WWW/HTTP :: Session Classifier: Topic :: Internet :: WWW/HTTP :: Site Management Classifier: Topic :: Security Classifier: Topic :: Software Development :: Libraries Classifier: Topic :: Software Development :: Libraries :: Python Modules onetimepass-1.0.1/onetimepass.egg-info/SOURCES.txt000066400000000000000000000003311404127044700217450ustar00rootroot00000000000000README.rst setup.py onetimepass/__init__.py onetimepass.egg-info/PKG-INFO onetimepass.egg-info/SOURCES.txt onetimepass.egg-info/dependency_links.txt onetimepass.egg-info/requires.txt onetimepass.egg-info/top_level.txtonetimepass-1.0.1/onetimepass.egg-info/dependency_links.txt000066400000000000000000000000011404127044700241320ustar00rootroot00000000000000 onetimepass-1.0.1/onetimepass.egg-info/requires.txt000066400000000000000000000000041404127044700224560ustar00rootroot00000000000000six onetimepass-1.0.1/onetimepass.egg-info/top_level.txt000066400000000000000000000000141404127044700226110ustar00rootroot00000000000000onetimepass onetimepass-1.0.1/onetimepass/000077500000000000000000000000001404127044700163725ustar00rootroot00000000000000onetimepass-1.0.1/onetimepass/__init__.py000077500000000000000000000207751404127044700205210ustar00rootroot00000000000000""" onetimepass module is designed to work for one-time passwords - HMAC-based and time-based. It is compatible with Google Authenticator application and applications based on it. @version: 1.0.1 @author: Tomasz Jaskowski @contact: http://github.com/tadeck @license: MIT >>> secret = b'MFRGGZDFMZTWQ2LK' >>> get_hotp(secret, 1) == 765705 True >>> get_hotp(secret, 1, as_string=True) == b'765705' True >>> valid_hotp(get_hotp(secret, 123), secret) 123 >>> valid_hotp(get_hotp(secret, 123), secret, last=123) False >>> valid_totp(get_totp(secret), secret) True >>> valid_totp(get_totp(secret)+1, secret) False >>> valid_hotp(get_totp(secret), secret) False >>> valid_totp(get_hotp(secret, 1), secret) False """ import base64 import hashlib import hmac import six import struct import time __author__ = 'Tomasz Jaskowski ' __date__ = '31 July 2015' __version_info__ = (1, 0, 1) __version__ = '%s.%s.%s' % __version_info__ __license__ = 'MIT' def _is_possible_token(token, token_length=6): """Determines if given value is acceptable as a token. Used when validating tokens. Currently allows only numeric tokens no longer than 6 chars. :param token: token value to be checked :type token: int or str :param token_length: allowed length of token :type token_length: int :return: True if can be a candidate for token, False otherwise :rtype: bool >>> _is_possible_token(123456) True >>> _is_possible_token(b'123456') True >>> _is_possible_token(b'abcdef') False >>> _is_possible_token(b'12345678') False """ if not isinstance(token, bytes): token = six.b(str(token)) return token.isdigit() and len(token) <= token_length def get_hotp( secret, intervals_no, as_string=False, casefold=True, digest_method=hashlib.sha1, token_length=6, ): """ Get HMAC-based one-time password on the basis of given secret and interval number. :param secret: the base32-encoded string acting as secret key :type secret: str or unicode :param intervals_no: interval number used for getting different tokens, it is incremented with each use :type intervals_no: int :param as_string: True if result should be padded string, False otherwise :type as_string: bool :param casefold: True (default), if should accept also lowercase alphabet :type casefold: bool :param digest_method: method of generating digest (hashlib.sha1 by default) :type digest_method: callable :param token_length: length of the token (6 by default) :type token_length: int :return: generated HOTP token :rtype: int or str >>> get_hotp(b'MFRGGZDFMZTWQ2LK', intervals_no=1) 765705 >>> get_hotp(b'MFRGGZDFMZTWQ2LK', intervals_no=2) 816065 >>> result = get_hotp(b'MFRGGZDFMZTWQ2LK', intervals_no=2, as_string=True) >>> result == b'816065' True """ if isinstance(secret, six.string_types): # It is unicode, convert it to bytes secret = secret.encode('utf-8') # Get rid of all the spacing: secret = secret.replace(b' ', b'') try: key = base64.b32decode(secret, casefold=casefold) except (TypeError): raise TypeError('Incorrect secret') msg = struct.pack('>Q', intervals_no) hmac_digest = hmac.new(key, msg, digest_method).digest() ob = hmac_digest[19] if six.PY3 else ord(hmac_digest[19]) o = ob & 15 token_base = struct.unpack('>I', hmac_digest[o:o + 4])[0] & 0x7fffffff token = token_base % (10 ** token_length) if as_string: # TODO: should as_string=True return unicode, not bytes? return six.b('{{:0{}d}}'.format(token_length).format(token)) else: return token def get_totp( secret, as_string=False, digest_method=hashlib.sha1, token_length=6, interval_length=30, clock=None, ): """Get time-based one-time password on the basis of given secret and time. :param secret: the base32-encoded string acting as secret key :type secret: str :param as_string: True if result should be padded string, False otherwise :type as_string: bool :param digest_method: method of generating digest (hashlib.sha1 by default) :type digest_method: callable :param token_length: length of the token (6 by default) :type token_length: int :param interval_length: length of TOTP interval (30 seconds by default) :type interval_length: int :param clock: time in epoch seconds to generate totp for, default is now :type clock: int :return: generated TOTP token :rtype: int or str >>> get_hotp(b'MFRGGZDFMZTWQ2LK', int(time.time())//30) == \ get_totp(b'MFRGGZDFMZTWQ2LK') True >>> get_hotp(b'MFRGGZDFMZTWQ2LK', int(time.time())//30) == \ get_totp(b'MFRGGZDFMZTWQ2LK', as_string=True) False """ if clock is None: clock = time.time() interv_no = int(clock) // interval_length return get_hotp( secret, intervals_no=interv_no, as_string=as_string, digest_method=digest_method, token_length=token_length, ) def valid_hotp( token, secret, last=1, trials=1000, digest_method=hashlib.sha1, token_length=6, ): """Check if given token is valid for given secret. Return interval number that was successful, or False if not found. :param token: token being checked :type token: int or str :param secret: secret for which token is checked :type secret: str :param last: last used interval (start checking with next one) :type last: int :param trials: number of intervals to check after 'last' :type trials: int :param digest_method: method of generating digest (hashlib.sha1 by default) :type digest_method: callable :param token_length: length of the token (6 by default) :type token_length: int :return: interval number, or False if check unsuccessful :rtype: int or bool >>> secret = b'MFRGGZDFMZTWQ2LK' >>> valid_hotp(713385, secret, last=1, trials=5) 4 >>> valid_hotp(865438, secret, last=1, trials=5) False >>> valid_hotp(713385, secret, last=4, trials=5) False """ if not _is_possible_token(token, token_length=token_length): return False for i in six.moves.xrange(last + 1, last + trials + 1): token_candidate = get_hotp( secret=secret, intervals_no=i, digest_method=digest_method, token_length=token_length, ) if token_candidate == int(token): return i return False def valid_totp( token, secret, digest_method=hashlib.sha1, token_length=6, interval_length=30, clock=None, window=0, ): """Check if given token is valid time-based one-time password for given secret. :param token: token which is being checked :type token: int or str :param secret: secret for which the token is being checked :type secret: str :param digest_method: method of generating digest (hashlib.sha1 by default) :type digest_method: callable :param token_length: length of the token (6 by default) :type token_length: int :param interval_length: length of TOTP interval (30 seconds by default) :type interval_length: int :param clock: time in epoch seconds to generate totp for, default is now :type clock: int :param window: compensate for clock skew, number of intervals to check on each side of the current time. (default is 0 - only check the current clock time) :type window: int (positive) :return: True, if is valid token, False otherwise :rtype: bool >>> secret = b'MFRGGZDFMZTWQ2LK' >>> token = get_totp(secret) >>> valid_totp(token, secret) True >>> valid_totp(token+1, secret) False >>> token = get_totp(secret, as_string=True) >>> valid_totp(token, secret) True >>> valid_totp(token + b'1', secret) False """ if _is_possible_token(token, token_length=token_length): if clock is None: clock = time.time() for w in range(-window, window+1): if int(token) == get_totp( secret, digest_method=digest_method, token_length=token_length, interval_length=interval_length, clock=int(clock)+(w*interval_length) ): return True return False __all__ = [ 'get_hotp', 'get_totp', 'valid_hotp', 'valid_totp' ] onetimepass-1.0.1/setup.cfg000066400000000000000000000000731404127044700156640ustar00rootroot00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 onetimepass-1.0.1/setup.py000066400000000000000000000041271404127044700155610ustar00rootroot00000000000000""" onetimepass module for HMAC-Based One-Time Passwords and Time-Based One-Time Passwords, as implemented in Google Authenticator. source: https://github.com/tadeck/onetimepass author: Tomasz Jaskowski (http://www.jaskowski.info/) """ try: from setuptools import setup except ImportError: from distutils.core import setup import os CURRENT_DIR = os.path.dirname(__file__) setup( author='Tomasz Jaskowski', author_email='tadeck@gmail.com', classifiers=[ 'Development Status :: 6 - Mature', 'Intended Audience :: Developers', 'Intended Audience :: Education', 'Intended Audience :: Financial and Insurance Industry', 'Intended Audience :: Healthcare Industry', 'Intended Audience :: Information Technology', 'Intended Audience :: Legal Industry', 'Intended Audience :: Science/Research', 'Intended Audience :: System Administrators', 'Intended Audience :: Telecommunications Industry', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Topic :: Internet :: WWW/HTTP :: Session', 'Topic :: Internet :: WWW/HTTP :: Site Management', 'Topic :: Security', 'Topic :: Software Development :: Libraries', 'Topic :: Software Development :: Libraries :: Python Modules', ], description='Module for generating and validating HOTP and TOTP tokens', download_url='https://github.com/tadeck/onetimepass/archive/v1.0.0.tar.gz', install_requires=[ # TODO: Assign it dynamically based on requirements.txt file content 'six', # tested with 1.3.0 and 1.9.0 ], license='MIT', long_description=open(os.path.join(CURRENT_DIR, 'README.rst')).read(), name='onetimepass', packages=['onetimepass'], url='https://github.com/tadeck/onetimepass/', version='1.0.1', )