def __init__(self, **kwargs): self._salt = None ts = now() # these should be set before setting salt # because salt actually depends on user created_at time if not "created_at" in kwargs: kwargs["created_at"] = ts self.created_at = ts if not "updated_at" in kwargs: kwargs["updated_at"] = ts self.updated_at = ts if "password_raw" in kwargs: password_raw = kwargs["password_raw"] del (kwargs["password_raw"]) kwargs["password_hash"] = pbkdf2_hex(password_raw, self.salt) StorableModel.__init__(self, **kwargs)
def test_pbkdf2(self): for case in self.TEST_DATA: data, salt, iterations, keylen, expected = case self.assertEqual(pbkdf2_hex(data, salt, iterations, keylen), expected)
def check_password(self, password_raw): return pbkdf2_hex(password_raw, self.salt) == self.password_hash
def set_password(self, password_raw): self.password_hash = pbkdf2_hex(password_raw, self.salt)
def set_password(self, password_raw): # Attention! Here follows a HACK. Supposed to be removed or at least investigated # why hmac requires str instead of unicode self.password_hash = pbkdf2_hex(str(password_raw), self.salt)