Ejemplo n.º 1
0
def calc(name, qtype):
    start_time = time.perf_counter()
    key = name + qtype
    d_id = hashing(name.encode()).hexdigest()[:28]
    c_id = hashing(key.encode()).hexdigest()
    end_time = time.perf_counter()
    calc_time = end_time - start_time
    return calc_time
Ejemplo n.º 2
0
def hash_file(file, directory=''):
    hasher = hashing()
    with open(directory + '\\' + file, 'rb') as afile:
        buf = afile.read(64)
        while len(buf) > 0:
            hasher.update(buf)
            buf = afile.read(64)
    # return hasher.digest()
    return hasher.hexdigest()
Ejemplo n.º 3
0
 def _addToCache(self, tp: str, data: dict, *args):
     self._loadCache()
     key = hashing(
         (str(tp) + ":" +
          ",".join(str(i) for i in args)).encode('utf-8')).hexdigest()
     if tp not in self._data:
         self._data[tp] = {key: {"date": time.time(), "data": data}}
     else:
         self._data[tp][key] = {"date": time.time(), "data": data}
     self._save()
Ejemplo n.º 4
0
 def _get(self, tp: str, *args, getAnyway: bool = False):
     self._loadCache()
     key = hashing(
         (str(tp) + ":" +
          ",".join(str(i) for i in args)).encode('utf-8')).hexdigest()
     if tp not in self._data:
         return None
     else:
         if key in self._data[tp]:
             if getAnyway:
                 return self._data[tp][key]['data']
             if self._validateDate(self._data[tp][key]['date'],
                                   time.time()):
                 return self._data[tp][key]['data']
             else:
                 # del self._data[tp][key]
                 # self._save()
                 return True
         else:
             return False
Ejemplo n.º 5
0
def valid_token(token, login, type):
    """Validate a security token. Type can be 'validate_email' or 'resetpwd' """
    conf = ConfReader('hedgehog.ini')
    s = str(conf.salt) + login + type
    return hashing(s).hexdigest() == token
Ejemplo n.º 6
0
 def calc(self, name, qtype):
     key = name + qtype
     d_id = hashing(name.encode()).hexdigest()[:2]
     c_id = hashing(key.encode()).hexdigest()
     return d_id, c_id