parameters: (user, token, secret, diff=2)
return_statement: return False
docstring: Validate a user/token/secret combination
      return true if the token is valid
      return false if the token is invalid
  
      :param user: The user to validate.
      :type user: str
      :param token: The token to use.
      :type token: int
      :param secret: The secret to use.
      :type secret: str
      :param diff: Variability in the token range.
      :type diff: 2
      :returns: True, False
docstring_summary: Validate a user/token/secret combination
      return true if the token is valid
      return false if the token is invalid
docstring_tokens: Validate a user / token / secret combination return true if the token is valid return false if the token is invalid
function: def valid_totp(user, token, secret, diff=2):
      """
      Validate a user/token/secret combination
      return true if the token is valid
      return false if the token is invalid
  
      :param user: The user to validate.
      :type user: str
      :param token: The token to use.
      :type token: int
      :param secret: The secret to use.
      :type secret: str
      :param diff: Variability in the token range.
      :type diff: 2
      :returns: True, False
      """
  
      if len(token) > 6:
          password = token[:-6]
          token = token[-6:]
      else:
          return False
      try:
          token = int(token)
      except:
          return False
      if secret:
          try:
              # an exception could occur if there is bad data supplied in the
              # secret, username or password
              # if this happens we fail authentication
              secret = decrypt_secret(secret, password, user)
          except:
              return False
          now = time.time() // 30
          for i in range(diff * -1, diff + 1):
              #print "valid - %s - %s (%s)" % (get_hotp_token(secret, int(now + i)), token, now + i)
              if get_hotp_token(secret, int(now + i)) == token:
                  return True
      return False
function_tokens: def valid_totp ( user , token , secret , diff = 2 ) : if len ( token ) > 6 : password = token [ : - 6 ] token = token [ - 6 : ] else : return False try : token = int ( token ) except : return False if secret : try : # an exception could occur if there is bad data supplied in the # secret, username or password # if this happens we fail authentication secret = decrypt_secret ( secret , password , user ) except : return False now = time . time ( ) // 30 for i in range ( diff * - 1 , diff + 1 ) : #print "valid - %s - %s (%s)" % (get_hotp_token(secret, int(now + i)), token, now + i) if get_hotp_token ( secret , int ( now + i ) ) == token : return True return False