def find_by(cls, **kw): from topdish.lib import security as securitylib if 'email' in kw: email = kw['email'] del kw['email'] kw['email_hash'] = securitylib.hash(email) return super(User, cls).find_by(**kw)
def generate_email_access_token(self, commit=True): from topdish.lib import security as securitylib expiry = (int(time.time()) / 86400 + 7) * 86400 token_text = '%s%s%s' % (expiry, self.email_hash, self.password_hash) self.email_access_token = securitylib.hash(token_text, salt=self.salt) self.email_access_token_expiry = expiry if commit: self.get_session().commit()
def check_password(self, cleartext): from topdish.lib import security as securitylib return securitylib.hash(cleartext, salt=self.salt) == self.password_hash
def _set_password(self, password): """ Set the user's password_hash to the hash of the new plaintext """ from topdish.lib import security as securitylib self.password_hash = securitylib.hash(password, salt=self.salt)
def before_update(self): from topdish.lib import security as securitylib super(User, self).before_update() if self.email: self.email_hash = securitylib.hash(self.email)