def attempt(self, username, password): r = self.redis h = Hasher() if not r.exists('username:%s' % username): raise AuthError() key = r.get('username:%s' % username) data = json.loads(r.get('user:%s' % key)) try: h.check(password, data['password']) except HashMismatch: raise AuthError() self.user = User(data=data, redis=r, key=key)
def decrypt(self, encryption_key): if self.data['destruct_key']: try: h = Hasher() h.check(encryption_key, self.data['destruct_key']) raise DestructKey() except (KeyError, HashMismatch): pass try: self.data['content'] = decrypt(encryption_key, \ self.data['content']).decode("UTF-8") except TypeError: pass self.decrypted = True self.encrypted = True
def _try_encrypt(self): try: if len(self.data['encryption_key']) >= 6: self.data['content'] = encrypt(self.data['encryption_key'], self.data['content']) self.encrypted = True self.enc_data['encrypted'] = True else: raise KeyError() if len(self.data['destruct_key']) > 0 \ and self.enc_data['encrypted']: h = Hasher(4) self.enc_data['destruct_key'] = h.hash( self.data['destruct_key']) except KeyError: self.enc_data['encrypted'] = False